From 251974456741feb0c420b9736c99801f1a599299 Mon Sep 17 00:00:00 2001 From: upgradingdave Date: Wed, 2 Nov 2016 10:49:00 -0400 Subject: [PATCH 1/2] add option to set ip address or host --- README.md | 2 +- src/pandeiro/boot_http.clj | 2 ++ src/pandeiro/boot_http/impl.clj | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f88dbac..2b25cdd 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ that can serve resources, directories or a typical ring handler. [](dependency) ```clojure -[pandeiro/boot-http "0.7.3"] ;; latest release +[pandeiro/boot-http "0.7.4-SNAPSHOT"] ;; latest release ``` [](/dependency) diff --git a/src/pandeiro/boot_http.clj b/src/pandeiro/boot_http.clj index b269b93..5035a8f 100644 --- a/src/pandeiro/boot_http.clj +++ b/src/pandeiro/boot_http.clj @@ -34,6 +34,7 @@ c cleanup SYM sym "A function to run after the server stops." r resource-root ROOT str "The root prefix when serving resources from classpath" p port PORT int "The port to listen on. (Default: 3000)" + I ip-or-host HOST str "The ip or host to listen on." k httpkit bool "Use Http-kit server instead of Jetty" s silent bool "Silent-mode (don't output anything)" R reload bool "Reload modified namespaces on each request." @@ -57,6 +58,7 @@ (def server (http/server {:dir ~dir, :port ~port, :handler '~handler, + :host ~ip-or-host :reload '~reload, :env-dirs ~(vec (:directories pod/env)), :httpkit ~httpkit, :not-found '~not-found, :resource-root ~resource-root})) diff --git a/src/pandeiro/boot_http/impl.clj b/src/pandeiro/boot_http/impl.clj index 503ebaf..799b472 100644 --- a/src/pandeiro/boot_http/impl.clj +++ b/src/pandeiro/boot_http/impl.clj @@ -119,12 +119,12 @@ :local-port (-> server .getConnectors first .getLocalPort) :stop-server #(.stop server)})) -(defn server [{:keys [port httpkit] :as opts}] +(defn server [{:keys [host port httpkit] :as opts}] ((if httpkit start-httpkit start-jetty) (-> (ring-handler opts) wrap-content-type wrap-not-modified) - {:port port :join? false})) + {:ip host :host host :port port :join? false})) ;; ;; nREPL From 852d93435cacadacb7c1005eb9fded2789e707ce Mon Sep 17 00:00:00 2001 From: upgradingdave Date: Wed, 2 Nov 2016 15:44:37 -0400 Subject: [PATCH 2/2] display host correctly in the stdout --- src/pandeiro/boot_http.clj | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pandeiro/boot_http.clj b/src/pandeiro/boot_http.clj index 5035a8f..fdb80fa 100644 --- a/src/pandeiro/boot_http.clj +++ b/src/pandeiro/boot_http.clj @@ -7,6 +7,7 @@ [boot.task.built-in :as task])) (def default-port 3000) +(def default-host "localhost") (def serve-deps '[[ring/ring-core "1.4.0"] @@ -48,6 +49,7 @@ (seq nrepl) (conj nrepl-dep)) worker (pod/make-pod (update-in (core/get-env) [:dependencies] into deps)) + host (or ip-or-host default-host) start (delay (pod/with-eval-in worker (require '[pandeiro.boot-http.impl :as http] @@ -58,7 +60,7 @@ (def server (http/server {:dir ~dir, :port ~port, :handler '~handler, - :host ~ip-or-host + :host ~host :reload '~reload, :env-dirs ~(vec (:directories pod/env)), :httpkit ~httpkit, :not-found '~not-found, :resource-root ~resource-root})) @@ -66,8 +68,9 @@ (when ~nrepl (http/nrepl-server {:nrepl ~nrepl}))) (when-not ~silent - (boot/info "Started %s on http://localhost:%d\n" + (boot/info "Started %s on http://%s:%d\n" (:human-name server) + ~host (:local-port server)))))] (when (and silent (not httpkit)) (silence-jetty!))