Skip to content

Commit a1d8825

Browse files
committed
fix(kit): fall back to the config origin when the resolved URL is unparsable
1 parent 07e0182 commit a1d8825

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

‎packages/kit/src/node/vite-host.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,16 @@ export function createViteDevToolsHost(options: CreateViteDevToolsHostOptions):
194194
},
195195
resolveOrigin() {
196196
const resolved = viteServer?.resolvedUrls?.local?.[0]
197-
if (resolved)
198-
return new URL(resolved).origin
197+
if (resolved) {
198+
try {
199+
return new URL(resolved).origin
200+
}
201+
catch {
202+
// `resolvedUrls` comes from the server, so a host or proxy plugin can
203+
// put anything here. Fall through to the config-derived origin instead
204+
// of throwing on a value we cannot parse.
205+
}
206+
}
199207
const https = !!viteConfig.server.https
200208
const host = typeof viteConfig.server.host === 'string' ? viteConfig.server.host : 'localhost'
201209
const port = viteConfig.server.port ?? (https ? 443 : 80)

0 commit comments

Comments
 (0)