webpack-dev-server
webpack-dev-server copied to clipboard
feat: make allowedHosts accept localhost subdomains by default
Use Case:
Some web applications will serve multiple domains and render different content depending on the incoming header. In a development environment, these applications may use localhost subdomains to simulate these alternative domains.
To reduce overall configuration, make the webpack-dev-server allow "localhost" as well as its subdomains. As "localhost" is already considered safe and convenient, the same can be said of its subdomains.
Available Workaround:
Without this feature, developing a multi-domain application requires configuring webpack-dev-server with:
allowedHosts: ".localhost"
- [ ] This is a bugfix
- [x] This is a feature
- [ ] This is a code refactor
- [ ] This is a test update
- [ ] This is a docs update
- [ ] This is a metadata update
For Bugs and Features; did you add new tests?
Yes.
Motivation / Use-Case
Some web applications will serve multiple domains and render different content depending on the incoming header. In a development environment, these applications may use localhost subdomains to simulate these alternative domains.
To reduce overall configuration, make the webpack-dev-server allow "localhost" as well as its subdomains. As "localhost" is already considered safe and convenient, the same can be said of its subdomains.
Breaking Changes
No.
Additional Info
Available Workaround:
Without this feature, developing a multi-domain application requires configuring webpack-dev-server with:
allowedHosts: ".localhost"
The committers listed above are authorized under a signed CLA.
- :white_check_mark: login: jdufresne / name: Jon Dufresne (f51ff8c231a2024b1eda0e805c72d56f531cd73d)
I think it is expected, because it is not standard, localhost is built-in loop, but *.localhost are not
localhost is built-in loop, but *.localhost are not
On Fedora Linux, all subdomains resolve to localhost out of the box:
$ gethostip localhost
localhost 127.0.0.1 7F000001
$ gethostip app1.localhost
localhost 127.0.0.1 7F000001
$ gethostip app2.localhost
localhost 127.0.0.1 7F000001
It is this fact that originally drew me using localhost subdomains as a viable workflow.
RFC 2606 states and reserves:
The ".localhost" TLD has traditionally been statically defined in host DNS implementations as having an A record pointing to the loop back IP address and is reserved for such use. Any other use would conflict with widely deployed code which assumes this use.
So it's unlikely other applications use .localhost or it has security implications.
@ylemkimon Yeah, I see, let's merge it
Codecov Report
Merging #4357 (8b52b2f) into master (088a318) will increase coverage by
0.00%. The diff coverage is100.00%.
@@ Coverage Diff @@
## master #4357 +/- ##
=======================================
Coverage 92.06% 92.06%
=======================================
Files 16 16
Lines 1638 1639 +1
Branches 616 617 +1
=======================================
+ Hits 1508 1509 +1
Misses 119 119
Partials 11 11
| Impacted Files | Coverage Δ | |
|---|---|---|
| lib/Server.js | 93.75% <100.00%> (+<0.01%) |
:arrow_up: |
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.