diff --git a/docs/config/server-options.md b/docs/config/server-options.md index a4031d6828e584..5263690dc28a80 100644 --- a/docs/config/server-options.md +++ b/docs/config/server-options.md @@ -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` diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index b3c10bccf92456..1e4328c5129b98 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -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 }