[vite 6.0.9] option server.allowedHosts doesn't take into account "true"
Problem
Describe the bug hi, i've recently updated vite to 6.0.9, the main change being the allowedHosts server conf field, it's said in the documentation that if set to true, it will accept any hosts, but even when setting it to true i get the error: Blocked request. This host ("hidden") is not allowed. To allow this host, add "hidden" to `server.allowedHosts` in vite.config.js. (maybe i could be dumb but it really doesn't seem to work) Reproduction google.com Steps to reproduce _No response_ System Info [code block] Used Package Manager npm Logs _No response_ Validations - [x] Follow our Code of Conduct - [x] Read the Contributing Guidelines. - [x] Read the docs. - [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate. - [x] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead. - [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server. - [x] The provided reproduction is a minimal reproducible example of the bug.
Error Output
error:
Blocked request. This host ("hidden") is not allowed.Unverified for your environment
Select your OS to check compatibility.
1 Fix
[vite 6.0.9] Fix server.allowedHosts not accepting 'true'
The issue arises because the server.allowedHosts option in Vite 6.0.9 is not correctly interpreting the boolean value 'true'. Instead of accepting any host, it is still enforcing host restrictions, leading to blocked requests. This could be due to a bug in the implementation or a misconfiguration in the Vite setup.
Awaiting Verification
Be the first to verify this fix
- 1
Check Vite Configuration
Ensure that the server.allowedHosts option is correctly set in your vite.config.js file. It should be explicitly set to true.
javascriptexport default { server: { allowedHosts: true } }; - 2
Clear Cache and Reinstall Dependencies
Sometimes, issues can arise from cached data or outdated dependencies. Clear the npm cache and reinstall the node modules to ensure everything is up to date.
bashnpm cache clean --force && rm -rf node_modules && npm install - 3
Update Vite to Latest Version
Check if there is a newer version of Vite available that may have fixed this issue. Update to the latest version if possible.
bashnpm install vite@latest - 4
Test with Different Hosts
After making the above changes, test your application with different hostnames to ensure that the server is now accepting requests from all hosts as expected.
bashcurl -H 'Host: hidden' http://localhost:3000
Validation
Confirm that you can access the Vite server from various hosts without receiving the 'Blocked request' error. If the issue persists, check the console logs for any additional error messages.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep