I have started a Compojure (Jetty) server with:
(defonce *server* (run-server {:host "localhost" :port 8080} "/*" (servlet routes)))
but netstat still shows that it is listening on 0.0.0.0:8080, i.e. all IPs.
What is the correct parameter to pass to run-server to make it listen on a single IP?
I think you're going to have to patch Compojure. It's not doing anything with your :host
parameter. Making this change to server/jetty.clj
seems to work, but I haven't tested it thoroughly.
(defn- create-server "Construct a Jetty Server instance." [options servlets] (let [port (options :port 80) host (options :host "0.0.0.0") connector (doto (org.mortbay.jetty.bio.SocketConnector.) (.setPort port) (.setHost host)) server (doto (Server.) (.addConnector connector)) servlets (partition 2 servlets)] (when (or (options :ssl) (options :ssl-port)) (add-ssl-connector! server options)) (doseq [[url-or-path servlet] servlets] (add-servlet! server url-or-path servlet)) server))
user> (run-server {:port 12346})
2009-07-22 13:48:53.999::INFO: jetty-6.1.15
2009-07-22 13:48:54.002::INFO: Started [email protected]:12346
nil
user> (run-server {:host "127.0.0.1" :port 12345})
2009-07-22 13:48:08.061::INFO: jetty-6.1.15
2009-07-22 13:48:08.129::INFO: Started [email protected]:12345
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With