Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix default host #1830

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Fix default host #1830

wants to merge 2 commits into from

Conversation

romanlex
Copy link

Default host is 0.0.0.0 by doc
image

Default host is 0.0.0.0 by doc
@vercel
Copy link

vercel bot commented Feb 22, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/jared/razzle/FmsTdbrxi4oqJ4rpmGXTNdo3BFf6
✅ Preview: https://razzle-git-fork-romanlex-patch-2-jared.vercel.app

@fivethreeo
Copy link
Collaborator

I think update docs instead of the code.

@romanlex
Copy link
Author

romanlex commented Mar 1, 2022

@fivethreeo ok, done

@gregmartyn
Copy link
Contributor

gregmartyn commented Apr 28, 2022

0.0.0.0 is not localhost. Localhost is 127.0.0.1; 0.0.0.0 is INADDR_ANY. The difference is that 0.0.0.0 listens on all network adapters, but 127.0.0.1 only listens for machine-local connections.

If you're running your site in a container/vm, your host will only be able to connect to the container if the container is listening on 0.0.0.0 and a port forward has been set up. If the container is listening on 127.0.0.1, it won't be able to connect -- only connections from the container itself can connect to it.

If you're not running inside a VM, using 127.0.0.1 is a little like having a firewall: other computers on your network won't be able to connect to it no matter what. 0.0.0.0 would allow those connections if you don't have a firewall configured.

More info: https://superuser.com/questions/949428/whats-the-difference-between-127-0-0-1-and-0-0-0-0

@romanlex
Copy link
Author

@gregmartyn it's pr changes only md files for consistency

@gregmartyn
Copy link
Contributor

I don't see how it's making it consistent though. Razzle listens on 0.0.0.0 by default as far as I can tell.

https://github.com/jaredpalmer/razzle/blob/master/packages/create-razzle-app/templates/default/src/index.js
does

express()
    .listen(port, function(err) {

which is https://expressjs.com/en/api.html#app.listen
which is https://nodejs.org/api/http.html#http_server_listen
which is https://nodejs.org/api/net.html#serverlistenport-host-backlog-callback
which says:
If host is omitted, the server will accept connections on the unspecified IPv6 address (::) when IPv6 is available, or the unspecified IPv4 address (0.0.0.0) otherwise.

In most operating systems, listening to the unspecified IPv6 address (::) may cause the net.Server to also listen on the unspecified IPv4 address (0.0.0.0).

@gregmartyn
Copy link
Contributor

gregmartyn commented Apr 29, 2022

Oh I see what you mean. Sorry!

devServer uses HOST here https://github.com/jaredpalmer/razzle/blob/master/packages/razzle/config/createConfigAsync.js#L854
for the port 3001 listener (aka PORT_DEV)
and on line 138 when CLIENT_PUBLIC_PATH wasn't set.

So we have a problem. HOST isn't being used by the prod server, but probably should be. A default of 0.0.0.0 would make sense for that, especially for backward compatibility. Otherwise you can't choose which network interface the production server listens on, which could be a problem if you want to have different services listening on different interfaces but the same port.

The dev server is defaulting to 127.0.0.1 for the PORT_DEV client-side build but the docs say 0.0.0.0. (The server-side build on PORT behaves the same as the prod build above) 127.0.0.1 makes sense as a safe default, but then it'd conflict with the new prod server default of 0.0.0.0. Further, the CLIENT_PUBLIC_PATH fallback is treating HOST as a routable address, but that wouldn't work for HOST=0.0.0.0.

Sounds to me like a separate var is in order. HOST_DEV (consistent with PORT_DEV, which already exists), defaulting to 127.0.0.1. What do y'all think?

@fivethreeo
Copy link
Collaborator

fivethreeo commented Apr 29, 2022

As long as it describes the behaviour it is all ok.

btw. I am close to stopping razzle development unless someone shares in the development. Considering just using next or plain webpack.

@romanlex
Copy link
Author

Next.js dictates how to organize a project ( routes example

@sergeysova
Copy link

sergeysova commented Jul 11, 2022

Hi!
How can I help you maintaining this project?
I think razzle is awesome, and I choose it again and again over Remix or Nextjs.

Thank you, for your work!

Original: #1159 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants