From 93cb7874bf5f40aef71bcc49c8ecd573d04a0499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Str=C3=B6mberg?= Date: Fri, 5 Dec 2025 23:07:09 +0100 Subject: [PATCH] Enable customizing the nrepl websocket port (#141) * Enable customizing the nrepl websocket port * Fixes #140 * Update changelog --- CHANGELOG.md | 1 + doc/nrepl/README.md | 10 ++++++++++ src/scittle/nrepl.cljs | 4 +++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddde1f0..b2fff67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ - [#114](https://github.com/babashka/scittle/issues/114): Enable source maps ([@jeroenvandijk](https://github.com/jeroenvandijk)) +- [#140](https://github.com/babashka/scittle/issues/140): Enable customizing the nrepl websocket port ([@PEZ](https://github.com/PEZ)) ## v0.7.28 (2025-09-13) diff --git a/doc/nrepl/README.md b/doc/nrepl/README.md index cf34934..5541357 100644 --- a/doc/nrepl/README.md +++ b/doc/nrepl/README.md @@ -42,6 +42,16 @@ you should be able evaluate expressions in `playground.cljs`. See a demo Note that the nREPL server connection stays alive even after the browser window refreshes. +### Custom host address + +By default, the browser will connect to a websocket on the same host as it is loaded +from, using `window.location.hostname`. If you need something else you can specify +that setting the window variable `SCITTLE_NREPL_WEBSOCKET_HOST` like so: + +``` html + +``` + ### CIDER Choose `cider-connect-cljs`, select port `1339`, followed by the `nbb` REPL diff --git a/src/scittle/nrepl.cljs b/src/scittle/nrepl.cljs index 08cb7bb..ec4c38c 100644 --- a/src/scittle/nrepl.cljs +++ b/src/scittle/nrepl.cljs @@ -8,7 +8,9 @@ (when-let [ws-port (.-SCITTLE_NREPL_WEBSOCKET_PORT js/window)] (set! (.-ws_nrepl js/window) - (new js/WebSocket (ws-url (.-hostname (.-location js/window)) ws-port "_nrepl")))) + (new js/WebSocket (ws-url (or (.-SCITTLE_NREPL_WEBSOCKET_HOST js/window) + (.-hostname (.-location js/window))) + ws-port "_nrepl")))) (when-let [ws (nrepl-server/nrepl-websocket)] (set! (.-onmessage ws)