Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make Compojure listen to a single IP

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?

like image 868
l0st3d Avatar asked Jul 22 '09 15:07

l0st3d


1 Answers

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
like image 154
Brian Carper Avatar answered Sep 28 '22 13:09

Brian Carper