Skip to content

feat(server): support multiple hosts in __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS#21501

Merged
sapphi-red merged 4 commits into
vitejs:mainfrom
ctate:ctate/allow-multi-hosts
Jun 2, 2026
Merged

feat(server): support multiple hosts in __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS#21501
sapphi-red merged 4 commits into
vitejs:mainfrom
ctate:ctate/allow-multi-hosts

Conversation

@ctate

@ctate ctate commented Jan 26, 2026

Copy link
Copy Markdown
Contributor

Allows __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS environment variable to accept multiple comma-separated hosts instead of just a single host.

# Before: single host only
__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=example.com

# After: multiple hosts supported
__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=example.com,test.com,dev.example.org
  • Splits the environment variable value by commas
  • Trims whitespace from each host
  • Filters out empty entries
  • Fully backwards compatible with single host values
  • Updated documentation (docs/config/server-options.md)
  • Included tests (6 new unit tests in config.spec.ts)

close #19746

@ctate ctate changed the title support multiple hosts in __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS feat(server): support multiple hosts in __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS Jan 26, 2026
@bluwy

bluwy commented Jan 28, 2026

Copy link
Copy Markdown
Member

The change looks good to me. Can you share a bit of your usecase here?

@ctate

ctate commented Jan 28, 2026

Copy link
Copy Markdown
Contributor Author

@bluwy Thanks for reviewing!

The use case is cloud-based development environments that can generate multiple hostnames for a single dev session. These platforms sometimes rotate or assign multiple preview URLs that all need to be allowed.

With the previous implementation only supporting a single host, devs would hit the "This host is not allowed" error and have to manually edit vite.config.js. This isn't ideal because those environment-specific changes could accidentally get committed and pushed to the repo.

By parsing the env var as comma-separated values, cloud IDEs can transparently configure all their hosts via the environment - no config file changes needed, nothing to accidentally commit.

bluwy
bluwy previously approved these changes Jan 29, 2026
@bluwy bluwy added this to Team Board Mar 6, 2026
@github-project-automation github-project-automation Bot moved this to Discussing in Team Board Mar 6, 2026
@bluwy

bluwy commented Mar 6, 2026

Copy link
Copy Markdown
Member

I just realized a similar PR was opened before: #19746. The discussion there was to have proper comma parsing, though for me I'm not sure we need it for now.

@bluwy bluwy added this to the 8.1 milestone Mar 9, 2026
@sapphi-red sapphi-red added the p2-nice-to-have Not breaking anything but nice to have (priority) label Mar 18, 2026
@sapphi-red sapphi-red moved this from Discussing to Approved in Team Board Mar 18, 2026
@sapphi-red

Copy link
Copy Markdown
Member

I've pushed a commit that reserves some characters for future use as we discussed in the team meeting.

@sapphi-red sapphi-red requested a review from bluwy June 2, 2026 03:36
@sapphi-red sapphi-red merged commit 735f9a1 into vitejs:main Jun 2, 2026
37 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p2-nice-to-have Not breaking anything but nice to have (priority)

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants