shadow-cljs icon indicating copy to clipboard operation
shadow-cljs copied to clipboard

Shadow server prints incorrect interface

Open ggeoffrey opened this issue 1 year ago • 6 comments

Shadow server will print on which interface and port it’s listening to:

shadow-cljs watch :app
shadow-cljs - starting via "clojure"
shadow-cljs - server version: 2.18.0 running at http://localhost:9630

By default, it will print "localhost" even though the actual default interface is "0.0.0.0". https://github.com/thheller/shadow-cljs/blob/d6e14905022b719d2e240646417f53d9ee452e4d/src/main/shadow/cljs/devtools/server.clj#L490-L494

This is problematic in environments like Repl.it where the system automatically detects ports opened on 0.0.0.0 and exposes them publicly.

This is fixed by setting {:http {:host "localhost"}} in shadow-cljs.edn.

I would expect shadow to print the actual interface it is listening to.

ggeoffrey avatar Jul 21 '22 16:07 ggeoffrey

The intent of that log line is something you can actually click and open a browser on.

http://0.0.0.0:9630 does not work, that is why the replacement is done. Not a bug and fully intentional.

This is problematic in environments like Repl.it where the system automatically detects ports opened on 0.0.0.0 and exposes them publicly.

I don't know how repl.it operates, so can you clarify why this is a problem? Surely it isn't looking for that exact log line?

thheller avatar Jul 21 '22 16:07 thheller

I understand this is about user experience. It’s a good tradeoff.

Repl.it watches two network interfaces at the OS level. A port opened on 0.0.0.0 is exposed to the outside world. Meaning Repl.it will forward all requests to https://<your-replit-instance>.repl.co to the first port opened on 0.0.0.0. Two ports opened on 0.0.0.0 might race for the public exposure. Repl.it documentation says: expose one port on 0.0.0.0 and the others on localhost.
Ports opened on localhost are not exposed.

Note: http://0.0.0.0:9630/ is clickable on my machine.

ggeoffrey avatar Jul 21 '22 17:07 ggeoffrey

This still doesn't clarify anything about why showing http://0.0.0.0:9630/ over http://localhost:9630/ changes anything? Neither will lead to the repl.it host?

Repl.it documentation says: expose one port on 0.0.0.0 and the others on localhost.

Can you point me to that location? I do not understand what this is supposed to tell me. There is only one port 9630 getting exposed so no clue what "race" this is referring to?

thheller avatar Jul 21 '22 17:07 thheller

Ah, my bad. Showing http://localhost:9630/ is misleading to the user. As a user, shadow is telling me it’s listening to localhost, while in fact it is listening to another interface.

There is only one port exposed by shadow, but there might be other ports exposed by the user’s app. For instance, my app exposes 8080 on 0.0.0.0 and should not expose the shadow server.

ggeoffrey avatar Jul 21 '22 17:07 ggeoffrey

Link to documentation https://docs.replit.com/hosting/deploying-http-servers

ggeoffrey avatar Jul 21 '22 17:07 ggeoffrey

I'm lost. What is the problem? You don't want the shadow-cljs server exposed? You already had the fix for that in the initial post?

thheller avatar Jul 21 '22 17:07 thheller