Skip to content

Commit

Permalink
Allow both VITE_HOST and the target to be allowedHosts
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanclark committed Jan 23, 2025
1 parent 1b8274d commit 0e8e356
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions web/packages/build/vite/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function createViteConfig(
const config: UserConfig = {
clearScreen: false,
server: {
allowedHosts: resolveAllowedHost(target),
allowedHosts: resolveAllowedHosts(target),
fs: {
allow: [rootDirectory, '.'],
},
Expand Down Expand Up @@ -196,18 +196,22 @@ export function createViteConfig(
});
}

function resolveAllowedHost(target: string) {
function resolveAllowedHosts(target: string) {
const allowedHosts = new Set<string>();

if (process.env.VITE_HOST) {
return [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(`http://${target}`);
const { hostname } = new URL(`https://${target}`);

return [hostname];
allowedHosts.add(hostname);
}

return [];
return Array.from(allowedHosts);
}

function resolveTargetURL(url: string) {
Expand Down

0 comments on commit 0e8e356

Please sign in to comment.