fix(devframe): advertise a dialable origin when bound to a wildcard host#89
Merged
Conversation
Binding the dev server to `0.0.0.0` (or `::`) makes it reachable on every interface, but that address isn't dialable from a browser — opening the printed `http://0.0.0.0:<port>` URL yields a page whose same-origin RPC WebSocket (`ws://0.0.0.0:<port>/__devframe_ws`) fails to connect. Map wildcard and loopback bind hosts to `localhost` when advertising the origin (ready banner, browser-open, dock/absolute URLs) and the baked WS endpoint, while still binding the socket to the wildcard host. This mirrors how Vite reports a `Local:` URL under `--host 0.0.0.0`.
✅ Deploy Preview for devfra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
The dialable-origin normalization in devframe/node/utils now also maps 127.0.0.1 to localhost when formatting the WS endpoint URL advertised by startHttpAndWs. Update the hub context test to match, and refresh the devframe/node tsnapi export snapshots for the new formatHostForUrl/toDialableHost exports.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Running a devframe dev server with
--host 0.0.0.0(as needed to reach a preview from outside the machine/container) prints and openshttp://0.0.0.0:<port>. A browser can't meaningfully connect to0.0.0.0— it's a bind-all address, not a routable host — so the SPA loads at that origin and its same-origin RPC socket fails:The WS descriptor is correctly same-origin/relative; the root cause is that the server advertises the wildcard bind host verbatim as its origin.
Fix
Map wildcard (
0.0.0.0,::, empty) and loopback (127.0.0.1) bind hosts to a dialablelocalhostwhen advertising a URL — the ready banner, browser-open target, dock/absolute origins, and the baked WS endpoint — while the socket still binds to the wildcard host and stays reachable on every interface. This mirrors how Vite reports itsLocal:URL under--host 0.0.0.0.toDialableHost/formatHostForUrladded tonode/utils.ts;normalizeHttpServerUrlnow handles wildcard hosts.startHttpAndWsbuildsoriginand the internalwsUrlthrough these helpers.createDevServeradvertises the dialable origin forresolveOrigin().Verification
Unit tests for the host mapping plus an integration test that binds
createDevServerto0.0.0.0and asserts the advertised origin ishttp://localhost:<port>and reachable.eslint,tsc --noEmit, and the affectedvitestsuites pass.This PR was created with the help of an agent.