Skip to content
Permalink
Browse files

improved port parsing

  • Loading branch information...
yogthos committed Jul 14, 2015
1 parent 277cd7e commit b69309110b48f2031427f92d9a99c6f7b0d39334
@@ -1,4 +1,4 @@
(defproject luminus/lein-template "2.8.4"
(defproject luminus/lein-template "2.8.5"
:description "a template for creating Luminus applications"
:url "https://github.com/yogthos/luminus-template"
:license {:name "MIT License"
@@ -12,7 +12,7 @@
['org.clojure/tools.reader "0.9.2"]
['reagent "0.5.0"]
['cljsjs/react "0.13.3-0"]
['reagent-forms "0.5.2"]
['reagent-forms "0.5.4"]
['reagent-utils "0.1.5"]
['secretary "1.2.3"]
['org.clojure/core.async "0.1.346.0-17112a-alpha"]
@@ -1,3 +1 @@
{:provided {:env {;;when set the application start the nREPL server on load
:nrepl-port "7001"<% if database-profiles %>
<<database-profiles>><% endif %>}}}
{:provided {:env {<% if database-profiles %><<database-profiles>><% endif %>}}}
@@ -52,7 +52,10 @@
<<cljs-dev>><% endif %>
<% if figwheel %>:figwheel
<<figwheel>><% endif %>
;;when set the application start the nREPL server on load

:repl-options {:init-ns <<project-ns>>.core}
:injections [(require 'pjstadig.humane-test-output)
(pjstadig.humane-test-output/activate!)]
:env {:dev true}}})
:env {:dev true
:nrepl-port 7001}}})
@@ -1,5 +1,5 @@
(ns <<project-ns>>.core
(:require [<<project-ns>>.handler :refer [app init destroy]]<% ifequal server "aleph" %>
(:require [<<project-ns>>.handler :refer [app init destroy parse-port]]<% ifequal server "aleph" %>
[aleph.http :as http]<% endifequal %><% ifequal server "http-kit" %>
[org.httpkit.server :as http-kit]<% endifequal %><% ifequal server "immutant" %>
[immutant.web :as immutant]<% endifequal %><% ifequal server "jetty" %>
@@ -9,13 +9,13 @@
[environ.core :refer [env]])
(:gen-class))
<% ifequal server "aleph" %>
(defn parse-port [[port]]
(Integer/parseInt (or port (env :port) "3000")))
(defn http-port [[port]]
(parse-port (or port (env :port) "3000")))

(defn start-app
"e.g. lein run 3000"
[args]
(let [port (parse-port args)]
(let [port (http-port args)]
(try
(init)
(.addShutdownHook (Runtime/getRuntime) (Thread. destroy))
@@ -53,7 +53,7 @@
(start-server args)
(timbre/info "server started on port:" (:port @server)))
<% else %>
(defn parse-port [[port]]
(defn http-port [[port]]
(Integer/parseInt (or port (env :port) "3000")))
<% ifequal server "http-kit" %>
(defn start-server [port]
@@ -83,8 +83,8 @@
(.stop @server)
(reset! server nil)))
<% endifequal %>
(defn start-app [args]
(let [port (parse-port args)]
(defn start-app [port]
(let [port (http-port port)]
(.addShutdownHook (Runtime/getRuntime) (Thread. stop-server))
(timbre/info "server is starting on port " port)
(start-server port)))
@@ -17,13 +17,20 @@
(route/resources "/")
(route/not-found "Not Found"))

(defn parse-port [port]
(when port
(cond
(string? port) (Integer/parseInt port)
(number? port) port
:else (throw (Exception. (str "invalid port value: " port))))))

(defn start-nrepl
"Start a network repl for debugging when the :nrepl-port is set in the environment."
[]
(when-let [port (env :nrepl-port)]
(try
(->> port
(Integer/parseInt)
(parse-port)
(nrepl/start-server :port)
(reset! nrepl-server))
(timbre/info "nREPL server started on port" port)

0 comments on commit b693091

Please sign in to comment.
You can’t perform that action at this time.