Fork me on GitHub
#shadow-cljs
<
2021-08-02
>
thheller05:08:51

@ellahoeppner if you need custom headers you'll need a server anyways. so you should use the server you plan on using in production for development as well

Ella Hoeppner19:08:28

Fair enough. Though the project I'm working on is just kinda a personal/prototyping thing and I doubt there will ever be a "production" version, so I was hoping for a simpler solution. I'll either look into making my own server or just using some old version of a browser that will let me use SharedArrayBuffers without special headers

Ella Hoeppner19:08:40

Thanks for your help!

mkarp17:08:38

Hey there! I have a question regarding the dynamic configuration of the :dev-http property. Suppose I have two http handlers configured in shadow-cljs.edn. If I launch clj and then call (start-server!), everything works as expected — I get two http servers:

$ cat shadow-cljs.edn
$ head -n 5 shadow-cljs.edn
{:deps true
 :nrepl {:port 7888}
 :socket-repl {:port 9002}
 :dev-http {9666 {:handler dev.handler/handler}
            9667 {:handler dev.handler2/handler}}

$ clj
Clojure 1.10.3
user=> (do (require '[shadow.cljs.devtools.server :as shadow.server])
           (def config (shadow.server/load-config))
           (shadow.server/start! config))
...
shadow-cljs - HTTP server available at  # 1️⃣ First server
...
shadow-cljs - HTTP server available at  # 2️⃣ Second server
...
:shadow.cljs.devtools.server/started
user=> 
Now I would like to turn on the second http server using a CLI argument. I remove the second http server from shadow-cljs.edn and configure it during runtime. For the simplicity of the example, I don't do any CLI arguments parsing here, but instead just prepare the config on the fly:
$ head -n 5 shadow-cljs.edn
{:deps true
 :nrepl {:port 7888}
 :socket-repl {:port 9002}
 :dev-http {9666 {:handler dev.handler/handler}
            #_#_9667 {:handler dev.handler2/handler}}

$ clj
Clojure 1.10.3
user=> (do (require '[shadow.cljs.devtools.server :as shadow.server])
           (def config (shadow.server/load-config))
           (def config* (assoc-in config [:dev-http 9667] {:handler 'dev.handler2/handler}))
           (shadow.server/start! config*))
...
shadow-cljs - HTTP server available at  # 1️⃣ Only the first server
...
:shadow.cljs.devtools.server/started
user=>
Though the configs are seemingly the same during runtime, second server doesn't start anymore. I'd appreciate any pointers to the solution!

Ryan Jerue18:08:30

When using the https://shadow-cljs.github.io/docs/UsersGuide.html#target-npm-module target, is there a way to not have the output export certain definitions? Ideally ones that are marked as private?

borkdude19:08:38

Do you mean :node-library?

Ryan Jerue19:08:03

Yes, :node-library . Should have copy/pasted 😅

thheller19:08:39

:npm-module is pretty much dead anyways so prefer to use :node-library if you can

👍 2
thheller19:08:08

but :npm-module already only exports things marked with ^:export

thheller19:08:22

@me1676 the dev-http stuff loads shadow-cljs.edn again and does not respect server/start! arguments. it loads the config itself since it automatically adjusts the servers if you change them while running

👍 3
thheller19:08:33

whats the point of starting it that way? my recommendation is always to use your own CLJ http server if you want anything beyond a basic static file server. even with just a :handler you should be using your own server. I even regret adding support for handler in the first place.

mkarp12:08:14

The point is convenience, I guess. Thank you for the answer! It's probably easier to start a separate server, yes