Skip to content

Separate the browser-facing origin from the dev server's bind address - #658

Merged
tricknotes merged 1 commit into
mainfrom
dev-server-origin
Sep 4, 2026
Merged

Separate the browser-facing origin from the dev server's bind address#658
tricknotes merged 1 commit into
mainfrom
dev-server-origin

Conversation

@tricknotes

@tricknotes tricknotes commented Sep 4, 2026

Copy link
Copy Markdown
Owner

Summary

The dev_server host option currently serves three purposes at once: the address the development server binds to, the address Rails connects to it on, and the origin the browser loads the application's assets from.

In a container those purposes conflict. The server must bind to 0.0.0.0 to be reachable through the container's published port, but a page then refers to its assets as http://0.0.0.0:4200/..., and browsers refuse to connect to 0.0.0.0 (Chrome blocks it under Local Network Access), so every asset request fails. Verified against a real application running under Docker Compose, with the browser on the host.

This PR splits the three purposes:

  • Add an origin option to dev_server, naming the browser-facing origin independently of host (e.g. dev_server: { host: "0.0.0.0", port: 4200, origin: "http://localhost:4200" }). A trailing slash is stripped. It defaults to http://<host>:<port>, as before.
  • DevServer#origin honors it, which covers both the index.html rewriting in Deploy::DevServer and the startup tags emitted by ember-cli-rails-assets 0.9.0 (the helper reads dev_server.origin), so no change is needed on the assets side.
  • Rails' own connections to the development server (request / listening?) now use the bind address instead of the origin, with 0.0.0.0 mapped to the loopback interface — the unspecified address asks the server to listen on every interface, but is not an address to connect to.

Also documents the container setup in the README and UPGRADING, and adds a CHANGELOG entry under the unreleased section.

Verified with the setup above (host: "0.0.0.0", port: 4200, published as 4200:4200, origin: "http://localhost:4200"): assets load and HMR works.

Notes

@tricknotes
tricknotes force-pushed the dev-server-asset-helpers branch from 48d7fc9 to fe2a21b Compare September 4, 2026 08:09
The dev_server `host` option served three purposes at once:
the address the development server binds to,
the address Rails connects to it on,
and the origin the browser loads the application's assets from.

In a container those purposes conflict:
the server must bind to `0.0.0.0` to be reachable through the container's published port,
but browsers refuse to connect to `http://0.0.0.0`,
so every asset request from the page fails.

Add an `origin` option naming the browser-facing origin independently of `host`.
`DevServer#origin` honors it,
which covers both the `index.html` rewriting in `Deploy::DevServer` and the startup tags emitted by ember-cli-rails-assets 0.9.0 (it reads `dev_server.origin`),
so no change is needed on the assets side.

Rails' own connections (`request` and `listening?`) now use the bind address rather than the origin,
with `0.0.0.0` mapped to the loopback interface,
since the unspecified address asks the server to listen everywhere but is not an address to connect to.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Base automatically changed from dev-server-asset-helpers to main September 4, 2026 08:20
@tricknotes
tricknotes merged commit 27d426c into main Sep 4, 2026
10 of 12 checks passed
@tricknotes
tricknotes deleted the dev-server-origin branch September 4, 2026 08:20
@tricknotes tricknotes mentioned this pull request Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants