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

Allow specifying hostname for Hapi servers. #12

Conversation

markdoliner-doma
Copy link

And specify it as "localhost" for the servers that are started by the integration tests.

Some of the integration tests were failing for me because:

  • My laptop is configured with both IPv4 and IPv6 for localhost (and non-localhost, too, but that's not relevant here).
  • Hapi binds to 0.0.0.0 by default (API docs, code reference).
  • That's an IPv4 address so the server will only accept connections over IPv4 and not IPv6.
  • Our integration test config specifies localhost when creating the clients for connecting to these servers.
  • localhost can resolve to an IPv6 address.
  • Node before v17 sorted IP addresses from the name resolver so IPv4 addresses were first but Node v17 and newer returns them in the order returned by the resolver (GitHub comment, relevant PR, it's the first "Other Notable Changes" in the v17.0.0 release notes). Apparently on my laptop an IPv6 address is returned before an IPv4 address.

Alternatively I could have changed the test config so clients connect to 127.0.0.1. I like this change because:

  • It's nice to allow users to specify the address to bind to anyway.
  • Now the test servers will bind to localhost instead of 0.0.0.0 and it's nice to avoid accepting outside connections when possible.

And specify it as "localhost" for the servers that are started by the integration tests.

Some of the integration tests were failing for me because:
- My laptop is configured with both IPv4 and IPv6 for localhost (and non-localhost, too, but that's not relevant here).
- Hapi binds to 0.0.0.0 by default ([API docs](https://hapi.dev/api/?v=20.2.2#-serveroptionsaddress), [code reference](https://github.com/hapijs/hapi/blob/b8ba0adc7c3255995cb56a9a740c4f9750b80e6b/lib/core.js#L339)).
- That's an IPv4 address so the server will only accept connections over IPv4 and not IPv6.
- Our integration test config specifies `localhost` when creating the clients for connecting to these servers.
- `localhost` can resolve to an IPv6 address.
- Node before v17 sorted IP addresses from the name resolver so IPv4 addresses were first but Node v17 and newer returns them in the order returned by the resolver ([GitHub comment](nodejs/node#40537 (comment)), [relevant PR](nodejs/node#39987), it's the first "Other Notable Changes" in [the v17.0.0 release notes](https://nodejs.org/en/blog/release/v17.0.0/#other-notable-changes)). Apparently on my laptop an IPv6 address is returned before an IPv4 address.

Alternatively I could have changed the test config so clients connect to 127.0.0.1. I like this change because:
- It's a good idea to allow users to specify the address to bind to.
- Now the test servers will bind to localhost instead of 0.0.0.0 and it's nice to avoid accepting outside connections when possible.
@markdoliner-doma markdoliner-doma merged commit 38fe76c into main Jul 6, 2022
@markdoliner-doma markdoliner-doma deleted the markdoliner-doma/Allow_specifying_hostname_for_hapi_servers branch July 6, 2022 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants