diff --git a/web/packages/build/vite/config.ts b/web/packages/build/vite/config.ts index 9521631ddf189..dec8a64bb7581 100644 --- a/web/packages/build/vite/config.ts +++ b/web/packages/build/vite/config.ts @@ -54,15 +54,10 @@ export function createViteConfig( } } - const targetHostname = - target !== DEFAULT_PROXY_TARGET - ? new URL(`http://${target}`).hostname - : undefined; - const config: UserConfig = { clearScreen: false, server: { - allowedHosts: targetHostname ? [`.${targetHostname}`] : [], + allowedHosts: resolveAllowedHosts(target), fs: { allow: [rootDirectory, '.'], }, @@ -172,6 +167,7 @@ export function createViteConfig( secure: false, }, }; + if (process.env.VITE_HTTPS_KEY && process.env.VITE_HTTPS_CERT) { config.server.https = { key: readFileSync(process.env.VITE_HTTPS_KEY), @@ -200,6 +196,24 @@ export function createViteConfig( }); } +function resolveAllowedHosts(target: string) { + const allowedHosts = new Set(); + + if (process.env.VITE_HOST) { + const { hostname } = new URL(`https://${process.env.VITE_HOST}`); + + allowedHosts.add(hostname); + } + + if (target !== DEFAULT_PROXY_TARGET) { + const { hostname } = new URL(`https://${target}`); + + allowedHosts.add(hostname); + } + + return Array.from(allowedHosts); +} + function resolveTargetURL(url: string) { if (!url) { return;