From 57276b723749e647b81f0a67c8c7b69303f95cf7 Mon Sep 17 00:00:00 2001 From: OneNail Date: Sat, 17 Dec 2022 02:59:07 -0800 Subject: [PATCH] fix: server and preview open fails to add slash before relative path (#11394) --- packages/vite/src/node/preview.ts | 2 +- packages/vite/src/node/server/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/preview.ts b/packages/vite/src/node/preview.ts index dd8180faa7dc3e..4a5d66838bad94 100644 --- a/packages/vite/src/node/preview.ts +++ b/packages/vite/src/node/preview.ts @@ -161,7 +161,7 @@ export async function preview( openBrowser( path.startsWith('http') ? path - : `${protocol}://${hostname.name}:${serverPort}${path}`, + : new URL(path, `${protocol}://${hostname.name}:${serverPort}`).href, true, logger, ) diff --git a/packages/vite/src/node/server/index.ts b/packages/vite/src/node/server/index.ts index f9e84ea1394b20..c069ddf852c3fa 100644 --- a/packages/vite/src/node/server/index.ts +++ b/packages/vite/src/node/server/index.ts @@ -679,7 +679,7 @@ async function startServer( openBrowser( path.startsWith('http') ? path - : `${protocol}://${hostname.name}:${serverPort}${path}`, + : new URL(path, `${protocol}://${hostname.name}:${serverPort}`).href, true, server.config.logger, )