Skip to content

Commit

Permalink
fix: server.host with ipv6 missed [] (fix vitejs#11466) (vitejs#11509)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun0day authored and futurGH committed Feb 26, 2023
1 parent d5e2a52 commit 801bc7f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
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 801bc7f

Please sign in to comment.