Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Setting `server.allowedHosts` to `true` allows any website to send requests to y
:::

::: details Configure via environment variable
You can set the environment variable `__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS` to add an additional allowed host.
You can use the environment variable `__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS` to add one or multiple additional allowed hosts, seperated by comma.
:::

## server.port
Expand Down
6 changes: 4 additions & 2 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1166,8 +1166,10 @@ export function resolveServerOptions(
process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS &&
Array.isArray(server.allowedHosts)
) {
const additionalHost = process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS
server.allowedHosts = [...server.allowedHosts, additionalHost]
const additionalHosts = process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS
.split(',')
.map((i) => i.replace(/^https?:\/\//, ''))
server.allowedHosts = [...server.allowedHosts, ...additionalHosts]
}

return server
Expand Down