replace hardcoded call to run-jetty to instead allow the caller to provide a function that will start the http server

This commit is contained in:
Gered 2014-11-16 13:57:46 -05:00
parent 81d027d382
commit 5912e2819e
2 changed files with 6 additions and 5 deletions

View file

@ -5,7 +5,7 @@
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.2.1"]
[org.clojure/core.incubator "0.1.0"]
[ring "1.2.1"]
[ring "1.3.1"]
[ring-refresh "0.1.2"]]
:plugins [[codox "0.6.6"]]
:profiles {:dev {:dependencies [[clj-http "0.4.1"]]}})

View file

@ -1,7 +1,6 @@
(ns ring.server.standalone
"Functions to start a standalone Ring server."
(:use ring.adapter.jetty
ring.server.options
(:use ring.server.options
ring.middleware.stacktrace
ring.middleware.reload
ring.middleware.refresh
@ -74,6 +73,8 @@
(defn serve
"Start a web server to run a handler. Takes the following options:
:run-server-fn - function that actually starts the server (e.g. run-jetty, run-jetty-async, etc).
the function should accept two arguments: handler and options
:port - the port to run the server on
:join? - if true, wait for the server to stop
:init - a function to run before the server starts
@ -88,7 +89,7 @@
If join? is false, a Server object is returned."
{:arglists '([handler] [handler options])}
[handler & [{:keys [init destroy join?] :as options}]]
[handler & [{:keys [init destroy join? run-server-fn] :as options}]]
(let [options (assoc options :join? false)
destroy (if destroy (memoize destroy))
handler (add-middleware handler options)]
@ -99,7 +100,7 @@
(try-port (port options)
(fn [port]
(let [options (merge {:port port} options)
server (run-jetty handler options)
server (run-server-fn handler options)
thread (add-destroy-hook server destroy)]
(println "Started server on port" (server-port server))
(if (open-browser? options)