feat(dev-server): support allowedHosts (Codespaces / ngrok / *.localhost) (#144) - #173
Merged
lukekania merged 1 commit intoMay 18, 2026
Conversation
Owner
Author
|
Closing to recreate the PR with the closing-keyword reference present at open time so GitHub auto-links #144. The branch is unchanged; commits and review history not needed yet. |
…lhost) (#144) Add the `allowedHosts` knob the `@angular/build:dev-server` builder exposes so projects fronted by a tunneling proxy (ngrok, Cloudflare Tunnel, GitHub Codespaces) or running under a non-default local hostname (`*.localhost`, `app.local`) don't get rejected by the dev server's `Host:` header check. * `packages/builder/schemas/dev-server.json`: add `allowedHosts: array`. * `packages/builder/src/serve/options.ts`: forward the list as `--allowed-hosts host1,host2`, normalizing empty/whitespace entries and case-insensitively deduping. * `crates/cli`: new `--allowed-hosts` flag on `ngc-rs serve` (value delimiter `,`) wired through `serve_cmd::run` to the dev server. * `crates/dev-server`: new `AllowedHosts` resolver + filter in `handle_request`. Loopback hosts (`localhost`, `127.0.0.1`, `[::1]`) are always allowed. The literal `"all"` disables the check entirely; `"auto"` (or an empty list, the default) additionally accepts the bound host. Anything else is an exact, case-insensitive hostname match with the `Host:`-header port stripped before comparison. Mismatches respond with a 403 whose body names the offending host and points at both the angular.json option and the CLI flag. Bumps workspace version to 0.10.12.
lukekania
force-pushed
the
feat/dev-server-allowed-hosts
branch
from
May 18, 2026 09:50
9a062df to
b2c5601
Compare
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.
Closes #144.
Summary
Honor the
allowedHostsarray on the dev-server builder so projects running behind tunneling proxies (ngrok, Cloudflare Tunnel, GitHub Codespaces) or non-default local hostnames (*.localhost,app.local) don't get rejected by the dev server'sHost:-header check.packages/builder/schemas/dev-server.json— newallowedHosts: { type: array, items: { type: string } }property.packages/builder/src/serve/options.ts— forwards the list tongc-rs serveas--allowed-hosts host1,host2, normalizing empty/whitespace entries and deduping case-insensitively on the way out.crates/cli/src/main.rs+serve_cmd.rs— new--allowed-hostsflag with a comma value delimiter, threaded throughrun/run_with_stopand intoDevServerConfig::with_allowed_hosts.crates/dev-server/src/lib.rs— newAllowedHostsresolver + filter inhandle_request. Loopback (localhost,127.0.0.1,[::1]) is always accepted. The literal"all"disables the check entirely;"auto"(or an empty list, the default) additionally accepts the bound host. Anything else is an exact, case-insensitive hostname match with theHost:port stripped before comparison. Mismatches return 403 with a body that names the offending host and points at botharchitect.serve.options.allowedHostsand the CLI flag.Bumps
[workspace.package].versionto0.10.12.Definition of done
"allowedHosts": ["my-app.ngrok.io"]lets ngrok-tunneled traffic through — covered byexplicit_allowed_host_lets_ngrok_traffic_throughincrates/dev-server/tests/integration.rs."allowedHosts": ["all"]disables the check entirely — covered byallowed_hosts_all_disables_check.default_allowed_hosts_accept_loopback_and_403_others, which also asserts the body mentions the host andallowedHosts.Test plan
cargo build --release -p ngc-rscargo test -p ngc-dev-server(21 tests pass, incl. 3 new integration tests + 9 new unit tests)cargo test -p ngc-rs --tests(all pre-existing tests pass;serve_help_lists_all_flagsupdated to assert--allowed-hostsis listed)cargo clippy --workspace -- -D warningsnpm testinpackages/builder(69 tests pass, incl. 4 newtranslateOptionscases forallowedHosts)