From 2c38bae9458794d42eebd7f7351f5633e2fe8247 Mon Sep 17 00:00:00 2001 From: sun0day Date: Wed, 28 Dec 2022 15:38:09 +0800 Subject: [PATCH] fix: server.host with ipv6 missed [] (fix #11466) (#11509) --- packages/vite/src/node/utils.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index d56b2fd5b8e302..fe325f5db4ec7e 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -867,10 +867,8 @@ export async function resolveServerUrls( if (hostname.host && loopbackHosts.has(hostname.host)) { let hostnameName = hostname.name - if ( - hostnameName === '::1' || - hostnameName === '0000:0000:0000:0000:0000:0000:0000:0001' - ) { + // ipv6 host + if (hostnameName.includes(':')) { hostnameName = `[${hostnameName}]` } local.push(`${protocol}://${hostnameName}:${port}${base}`) @@ -886,7 +884,11 @@ export async function resolveServerUrls( (typeof detail.family === 'number' && detail.family === 4)), ) .forEach((detail) => { - const host = detail.address.replace('127.0.0.1', hostname.name) + let host = detail.address.replace('127.0.0.1', hostname.name) + // ipv6 host + if (host.includes(':')) { + host = `[${host}]` + } const url = `${protocol}://${host}:${port}${base}` if (detail.address.includes('127.0.0.1')) { local.push(url)