Skip to content

Commit

Permalink
fix: server.host with ipv6 missed [] (fix #11466) (#11509)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day committed Dec 28, 2022
1 parent 13ac37d commit 2c38bae
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/vite/src/node/utils.ts
Expand Up @@ -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}`)
Expand All @@ -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)
Expand Down

0 comments on commit 2c38bae

Please sign in to comment.