Skip to content

Commit

Permalink
fix: try parse server.origin URL (#19241)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluwy authored Jan 20, 2025
1 parent a55f8ba commit 2495022
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/vite/src/node/server/middlewares/hostCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export function getAdditionalAllowedHosts(
// allow server origin by default as that indicates that the user is
// expecting Vite to respond on that host
if (resolvedServerOptions.origin) {
const serverOriginUrl = new URL(resolvedServerOptions.origin)
list.push(serverOriginUrl.hostname)
// some frameworks may pass the origin as a placeholder, so it's not
// possible to parse as URL, so use a try-catch here as a best effort
try {
const serverOriginUrl = new URL(resolvedServerOptions.origin)
list.push(serverOriginUrl.hostname)
} catch {}
}

return list
Expand Down

0 comments on commit 2495022

Please sign in to comment.