fix: use same host for websocket server as for http server when previewing locally #1309
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What/Why/How?
Today the WS server used for hot reloading is initialized without specifying a host. But in the
hot.js
file,127.0.0.1
is hardcoded as the host it should connect to. This breaks in some cases, such as when the websocket server binds to ipv6, and therefore isn't available on127.0.0.1
.This PR changes it so that the host provided via
--host
or-h
is passed on to the WS server as well, not only to the http server. It also adds this host as a global variable, alongside thewsPort
variable, so thathot.js
can pick up the correct host when connecting to the websocket; instead of the hardcoded host today.Testing
No tests seem to exist for the preview-server functionality and I have not added any. Instead I have tested manually with a variety of commonly used hosts (
::
,0.0.0.0
,::1
,localhost
,127.0.0.1
) to confirm that they work.Check yourself
Security