From 20e125dd6c624f8d1ce234c18034bc152446d1fb Mon Sep 17 00:00:00 2001 From: Srijayanth Sridhar <131062+craftybones@users.noreply.github.com> Date: Tue, 18 Oct 2022 19:31:40 +0530 Subject: [PATCH] Fix scittle.nrepl to honor SCITTLE_NREPL_WEBSOCKET_PORT Add (deref (promise)) to doc/nrepl/bb.edn:http-server --- doc/nrepl/bb.edn | 3 ++- src/scittle/nrepl.cljs | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/doc/nrepl/bb.edn b/doc/nrepl/bb.edn index ddc1105..8efe856 100644 --- a/doc/nrepl/bb.edn +++ b/doc/nrepl/bb.edn @@ -5,7 +5,8 @@ :tasks {http-server {:doc "Starts http server for serving static files" :requires ([babashka.http-server :as http]) :task (do (http/serve {:port 1341 :dir "."}) - (println "Serving static assets at http://localhost:1341"))} + (println "Serving static assets at http://localhost:1341") + (deref (promise)))} browser-nrepl {:doc "Start browser nREPL" :requires ([sci.nrepl.browser-server :as bp]) diff --git a/src/scittle/nrepl.cljs b/src/scittle/nrepl.cljs index e7fcad2..801a373 100644 --- a/src/scittle/nrepl.cljs +++ b/src/scittle/nrepl.cljs @@ -31,9 +31,12 @@ :complete (let [completions (completions (assoc msg :ctx @!sci-ctx))] (nrepl-reply msg completions)))) -(when (.-SCITTLE_NREPL_WEBSOCKET_PORT js/window) +(defn ws-url [host port path] + (str "ws://" host ":" port "/" path)) + +(let [ws-port (or (.-SCITTLE_NREPL_WEBSOCKET_PORT js/window) 1340)] (set! (.-ws_nrepl js/window) - (new js/WebSocket "ws://localhost:1340/_nrepl"))) + (new js/WebSocket (ws-url "localhost" ws-port "_nrepl")))) (when-let [ws (nrepl-websocket)] (prn :ws ws)