Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: try parse server.origin URL #19241

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this have a debug log at least? quiet swallowing can lead to long and frustrating debug sessions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can add one, yes, but I don't expect that this fix will stay in place

}

return list
Expand Down
Loading