diff --git a/src/ring/server/options.clj b/src/ring/server/options.clj index 74ac9df..aa67dc0 100644 --- a/src/ring/server/options.clj +++ b/src/ring/server/options.clj @@ -1,8 +1,6 @@ (ns ring.server.options "Functions to retrieve options and settings with sensible defaults" (:use ring.util.environment - ring.middleware.stacktrace - ring.middleware.reload [clojure.core.incubator :only (-?>)])) (def dev-env? @@ -22,8 +20,12 @@ [options] (:open-browser? options dev-env?)) -(defn middleware +(defn auto-reload? + "True if the source files should be automatically reloaded." [options] - (or (:middleware options) - (if dev-env? - [wrap-stacktrace wrap-reload]))) + (:auto-reload? options dev-env?)) + +(defn stacktraces? + "True if stacktraces should be shown for exceptions raised by the handler." + [options] + (:stacktraces? options dev-env?)) diff --git a/src/ring/server/standalone.clj b/src/ring/server/standalone.clj index 82c5652..8b79e84 100644 --- a/src/ring/server/standalone.clj +++ b/src/ring/server/standalone.clj @@ -2,6 +2,8 @@ "Functions to start a standalone Ring server." (:use ring.adapter.jetty ring.server.options + ring.middleware.stacktrace + ring.middleware.reload [clojure.java.browse :only (browse-url)])) (defn- try-port @@ -47,11 +49,20 @@ (try (.join server) (finally (if destroy (destroy)))))) +(defn- add-stacktraces [handler options] + (if (stacktraces? options) + (wrap-stacktrace handler) + handler)) + +(defn- add-auto-reload [handler options] + (if (auto-reload? options) + (wrap-reload handler) + handler)) + (defn- add-middleware [handler options] - (reduce - (fn [h m] (m h)) - handler - (middleware options))) + (-> handler + (add-stacktraces options) + (add-auto-reload options))) (defn serve "Start a web server to run a handler. Takes the following options: @@ -60,7 +71,8 @@ :init - a function to run before the server starts :destroy - a function to run after the server stops :open-browser? - if true, open a web browser after the server starts - :middleware - a list of middleware functions to apply to the handler + :stacktraces? - if true, display stacktraces when an exception is thrown + :auto-reload? - if true, automatically reload source files If join? is false, a Server object is returned." {:arglists '([handler] [handler options])}