Skip to content

Commit 4d88f6c

Browse files
authored
feat: support for env var for defining allowed hosts (#19325)
1 parent fdb36e0 commit 4d88f6c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

docs/config/server-options.md

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ If a string starts with `.`, it will allow that hostname without the `.` and all
5656
If set to `true`, the server is allowed to respond to requests for any hosts.
5757
This is not recommended as it will be vulnerable to DNS rebinding attacks.
5858

59+
::: details Configure via environment variable
60+
You can set the environment variable `__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS` to add an additional allowed host.
61+
:::
62+
5963
## server.port
6064

6165
- **Type:** `number`

packages/vite/src/node/server/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -1154,6 +1154,14 @@ export function resolveServerOptions(
11541154
)
11551155
}
11561156

1157+
if (
1158+
process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS &&
1159+
Array.isArray(server.allowedHosts)
1160+
) {
1161+
const additionalHost = process.env.__VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS
1162+
server.allowedHosts = [...server.allowedHosts, additionalHost]
1163+
}
1164+
11571165
return server
11581166
}
11591167

0 commit comments

Comments
 (0)