Skip to content
Merged
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
4 changes: 4 additions & 0 deletions docs/config/server-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ If a string starts with `.`, it will allow that hostname without the `.` and all
If set to `true`, the server is allowed to respond to requests for any hosts.
This is not recommended as it will be vulnerable to DNS rebinding attacks.

::: details Configure via environment variable
You can set the environment variable `__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS` to add an additional allowed host.
:::

## server.port

- **Type:** `number`
Expand Down
8 changes: 8 additions & 0 deletions packages/vite/src/node/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,14 @@ export function resolveServerOptions(
)
}

if (
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]
}

return server
}

Expand Down