Fork me on GitHub
#shadow-cljs
<
2024-01-15
>
seepel06:01:48

Hi there, I currently have my dev setup so that my server clojure code get’s called by the :dev-http :handler configuration parameter This has been a great setup so far that lets me have a single repl between server/client, but now I have to integrate server-sent events. I’m not exactly sure how everything is wired up in shadow-cljs, but my understanding is that what I want to do for my real server code is to call run-jetty with the :async true flag. Then my ring handlers would look like (defn handler [request response raise] …) Is there a way to set this up so that I can have a single repl connection for the shadow-cljs browser window and my clj server code?

thheller10:01:03

don't tell :dev-http about your handler at all, and don't tell your CLJ server about shadow-cljs at all

thheller10:01:16

just start shadow-cljs in the process you use for your http server

thheller10:01:14

basically in the start function you'd start your http server and the shadow-cljs server+builds

thheller10:01:40

(note that it is never necessary to stop the shadow-cljs server, but might be useful for some things you start)

seepel23:01:30

After following this blog post: https://blog.agical.se/en/posts/shadow-cljs-clojure-cljurescript-calva-nrepl-basics/ I ended up with this

(def jetty
  (jetty/run-jetty #'app/handler
                   {:port 8080
                    :join? false
                    :async? true}))

(shadow.cljs.devtools.server/start!)
(shadow.cljs.devtools.api/watch :app)
(shadow.cljs.devtools.api/nrepl-select :app)
And I removed the shadow-cljs dev server all together. Does that seem right?

seepel23:01:33

Oh shoot, except now I can’t toggle between clj and cljs using calva Turns out if I use one of the shadow-cljs jack in options from calva then this works.

thheller07:01:35

can't comment on anything calva since I don't use it

thheller07:01:01

but if it does what you need it is probably fine 🙂 :dev-http is always optional and not needed if you have your own server

seepel18:01:11

Great, thank you for the pointers!