我正在使用使用 ring/compojure 的 luminus Web 框架运行服务器,并且我希望能够使用 clojure repl 连接到我的代码。我知道有一个nrepl
代表网络复制的服务器,您可以通过以下方式连接到它:`lein repl :connect user@host:port (或一些不同的协议,我已经尝试了一些东西)。
以下代码repl.clj
是在您使用 `lein new luminus [project-name] 自动生成 luminus 项目时创建的(实际上我添加了附加 clojurescript repl 所需的 browser-repl 片段)。
(ns sophia-site.repl
(:require [cemerick.piggieback :as pig]
[weasel.repl.websocket])
(:use sophia-site.handler
ring.server.standalone
[ring.middleware file-info file]))
(defn browser-repl []
(pig/cljs-repl :repl-env
(weasel.repl.websocket/repl-env :ip "localhost" :port 9001)))
(defonce server (atom nil))
(defn get-handler []
;; #'app expands to (var app) so that when we reload our code,
;; the server is forced to re-resolve the symbol in the var
;; rather than having its own copy. When the root binding
;; changes, the server picks it up without having to restart.
(-> #'app
; Makes static assets in $PROJECT_DIR/resources/public/ available.
(wrap-file "resources")
; Content-Type, Content-Length, and Last Modified headers for files in body
(wrap-file-info)))
(defn start-server
"used for starting the server in development mode from REPL"
[& [port]]
(let [port (if port (Integer/parseInt port) 8080)]
(reset! server
(serve (get-handler)
{:port port
:init init
:auto-reload? true
:destroy destroy
:join? false}))
(println (str "You can view the site at http://some-ip:" port))))
(defn stop-server []
(.stop @server)
(reset! server nil))
我一直不成功lein repl :connect ...
- 如何将 clojure repl 附加到服务器上的代码?
感谢所有的帮助