Skip to content

Commit

Permalink
feat: support for env var for defining allowed hosts (#19325)
Browse files Browse the repository at this point in the history
  • Loading branch information
CompuIves authored Feb 5, 2025
1 parent fdb36e0 commit 4d88f6c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit 4d88f6c

Please sign in to comment.