Problems connecting to clojure nREPL with / compojure ring

Running Leiningen 2.3.4 on Java 1.7.0_21 HotSpot (TM) Java Server with 64-bit Server

I'm having trouble connecting to the nREPL server.

I set up a new project with lein new luminus, and then add a dependency for drawbridge ( [com.cemerick/drawbridge "0.0.6"]).

I added a handler route for repl as follows (based on https://devcenter.heroku.com/articles/debugging-clojure ):

(def drawbridge-handler
  (-> (cemerick.drawbridge/ring-handler)
      (wrap-keyword-params)
      (wrap-nested-params)
      (wrap-params)
      (wrap-session)))

(defn wrap-drawbridge [handler]
  (fn [req]
    (if (= "/repl" (:uri req))
      (drawbridge-handler req)
      (handler req))))

And added wrap-drawbridgeto my means.

Then I start the server using

lein ring server-headless

The connection works well because executing a GET request http:localhost:3000/repldoes not give an answer:["[\n","\n]"]

But I can not connect to REPL:

> lein repl :connect 0.0.0.0:3000/repl
Connecting to nREPL at 0.0.0.0:3000/repl

And after a while:

SocketException The transport socket appears to have lost its connection to the nREPL server
    clojure.tools.nrepl.transport/bencode/fn--4287/fn--4288 (transport.clj:95)
    clojure.tools.nrepl.transport/bencode/fn--4287 (transport.clj:95)
    clojure.tools.nrepl.transport/fn-transport/fn--4261 (transport.clj:42)
    clojure.core/binding-conveyor-fn/fn--4107 (core.clj:1836)
    java.util.concurrent.FutureTask$Sync.innerRun (FutureTask.java:334)
    java.util.concurrent.FutureTask.run (FutureTask.java:166)
    java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1145)
    java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:615)
    java.lang.Thread.run (Thread.java:722)
Bye for now!

Did I miss something?

Edit:

The following registration code has been added for my handler:

(defn wrap-drawbridge [handler]
  (fn [req]
    (if (= "/repl" (:uri req))
      (do (println "IN REPL ")
        (drawbridge-handler req))
      (handler req))))

lein repl :connect http://localhost:3000/repl, , , IN REPL .

+4
3

, , .

Luminus project-name.repl, .

, , , project.clj

:repl-options {
                  :init-ns project-name.repl
                  :init (start-server)}

lein repl.

, nREPL!

+5

, (, )?

, , , lein repl :connect - , IP/Port URL-. drawbridge, , nREPL HTTP, :

lein repl :connect http://localhost:3000/repl
+1

You need to add wrap-drawbridgefirst to the middleware list.

If you do something like this

(def app (-> #'all-routes
               wrap-drawbridge
               ...
               ...
               ...
               ))

It works like a charm.

0
source

All Articles