Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #72 from james-henderson/master

nREPL support
  • Loading branch information...
commit 6f73354ab82b3f450a0afe93b6b7eb8ab4273ba6 2 parents 5590f18 + 9adc5d0
@weavejester authored
Showing with 30 additions and 4 deletions.
  1. +5 −0 README.md
  2. +25 −4 src/leiningen/ring/server.clj
View
5 README.md
@@ -109,6 +109,11 @@ The following options affect the behavior of the web server started by
If true, automatically refresh the browser when source or resource
files are modified. Defaults to false.
+* `:nrepl` -
+ A map of `:start?` and (optionally) `:port` keys. If `:start?` is true,
+ open up an nREPL server on the given port. `:start?` defaults to false,
+ `:port` defaults to an arbitrary free port.
+
## Executable jar files
Lein-Ring can generate executable jar files for deployment purposes:
View
29 src/leiningen/ring/server.clj
@@ -26,8 +26,27 @@
(or (get-in project [:ring :reload-paths])
(classpath-dirs project)))
+(defn add-dep [project dep]
+ (update-project project deps/add-if-missing dep))
+
(defn add-server-dep [project]
- (update-project project deps/add-if-missing '[ring-server/ring-server "0.2.8"]))
+ (add-dep project '[ring-server/ring-server "0.2.8"]))
+
+(defn start-server-expr [project]
+ `(ring.server.leiningen/serve '~(select-keys project [:ring])))
+
+(defn nrepl? [project]
+ (-> project :ring :nrepl :start?))
+
+(defn add-optional-nrepl-dep [project]
+ (if (nrepl? project)
+ (add-dep project '[org.clojure/tools.nrepl "0.2.2"])
+ project))
+
+(defn start-nrepl-expr [project]
+ (let [port (-> project :ring :nrepl (:port 0))]
+ `(let [{port# :port} (clojure.tools.nrepl.server/start-server :port ~port)]
+ (println "Started nREPL server on port" port#))))
(defn server-task
"Shared logic for server and server-headless tasks."
@@ -37,11 +56,13 @@
(assoc-in [:ring :reload-paths] (reload-paths project))
(update-in [:ring] merge options))]
(eval-in-project
- (add-server-dep project)
- `(ring.server.leiningen/serve
- '~(select-keys project [:ring]))
+ (-> project add-server-dep add-optional-nrepl-dep)
+ (if (nrepl? project)
+ `(do ~(start-nrepl-expr project) ~(start-server-expr project))
+ (start-server-expr project))
(load-namespaces
'ring.server.leiningen
+ (if (nrepl? project) 'clojure.tools.nrepl.server)
(-> project :ring :handler)
(-> project :ring :init)
(-> project :ring :destroy)))))
Please sign in to comment.
Something went wrong with that request. Please try again.