4 ms·
One recent frustration I ran into with Node's DNS is that it doesn't seem to resolve whatever.localhost to 127.0.0.1, unlike my browser. Not entirely sure whic
by lewisl9029 5y ago
One recent frustration I ran into with Node's DNS is that it doesn't seem to resolve whatever.localhost to 127.0.0.1, unlike my browser.
Not entirely sure which is doing the right thing by the spec here, but I much prefer the browser behavior, because I would really like to not have to add a hosts entry for everything I reverse proxy from Caddy for doing local HTTPS/HTTP2 development for production parity.
Oh, and I also found out that Node also isn't able to use the system-wide certs store (which local HTTPS in Caddy adds to) [1], so in the end even adding a hosts entry didn't work, and I had to revert to plaintext HTTP1. Deno is looking more attractive every day [2]. Too bad I can't use it for building VSCode extensions.
Really curious to hear how other folks are doing local HTTPS/HTTP2 setups in node these days.
[1] https://github.com/nodejs/node/issues/3159 https://github.com/nodejs/node/issues/3159
[2] https://github.com/denoland/deno/pull/11491 https://github.com/denoland/deno/pull/11491
- withinboredom 5y agoNode (community?) does a lot of weird things when it comes to localhost. No idea if this is still true, but a lot of libraries/servers bound to 127.0.0.1 instead of localhost. Watching it explode in an ipv6 environment was cute. Then there was Docker and that didn’t work because the socket wasn’t bound to a public socket. I don’t know what 0.0.0.0 wasn’t the default in these libraries. Maybe it was a hint it wasn’t to be used in production…
- mhio 5y ago> resolve whatever.localhost to 127.0.0.1 I think that's the browsers making names up. No system resolvers I've seen respond to an x.localhost lookup. I generally have a wildcard setup on an internal domain for generic local names (*.local.me) > Node also isn't able to use the system-wide certs store Node can use the `NODE_EXTRA_CA_CERTS` environment variable to add a file of one or more PEM trusted certificates at launch. https://nodejs.org/dist/latest-v16.x/docs/api/cli.html#node_extra_ca_certsfile https://nodejs.org/dist/latest-v16.x/docs/api/cli.html#node_...
- lewisl9029 5y ago> I think that's the browsers making names up. No system resolvers I've seen respond to an x.localhost lookup. Fair enough, I guess I just wish node would behave more like a browser in this case then, as it'd have saved me a lot of headache. > I generally have a wildcard setup on an internal domain for generic local names (*.local.me) Curious how you set that up? Hosts files don't allow wildcards afaik, and that's what I've been struggling with. > Node can use the `NODE_EXTRA_CA_CERTS` environment variable to add a file of one or more PEM trusted certificates at launch. I actually tried this option briefly but couldn't get it to work, at least not with the root cert that Caddy generated. I would much prefer a `NODE_USE_SYSTEM_CERTS` option that doesn't require pointing to any specific paths though, as there's less room for misconfiguration, which I can't rule out in my case.
- mhio 5y ago> Curious how you set that up? Via a DNS server we run, that then answers for local things or forwards requests on to the real world. To do that locally, set up a DNS forwarder like dnsmasq [0] or unbound [1] (or coredns/bind/etc) to respond for the domain you want to wildcard to localhost. Point your OS DNS settings to 127.0.0.1, then configure the forwarder with your regular external DNS servers. The equivalent to `NODE_USE_SYSTEM_CERTS` is a build time option unfortunately. I know the rhel/debian packages do integrate their builds with the system CA's but those packages tend to be ancient. Maybe try the nodesource [2] packaged node.js? The homebrew node formulae [3] looks like it integrates with the brew openssl CA's. [0] https://stackoverflow.com/a/22551303 https://stackoverflow.com/a/22551303 [1] https://unbound.docs.nlnetlabs.nl/en/latest/manpages/unbound.conf.html#:~:text=for%20AAAA%20queries.-,redirect,-The%20query%20is https://unbound.docs.nlnetlabs.nl/en/latest/manpages/unbound... [2] https://github.com/nodesource/distributions https://github.com/nodesource/distributions [3] https://github.com/Homebrew/homebrew-core/blob/c2579d98415bdc802ecc85e40af250f46a357037/Formula/node.rb#L96 https://github.com/Homebrew/homebrew-core/blob/c2579d98415bd...