Skip to content

Commit

Permalink
fix: only show the listened IP when host is specified (#13412)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jun 3, 2023
1 parent bf0cd25 commit 20b0cae
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/vite/src/node/utils.ts
Expand Up @@ -881,13 +881,18 @@ export async function resolveServerUrls(
const base =
config.rawBase === './' || config.rawBase === '' ? '/' : config.rawBase

if (hostname.host && loopbackHosts.has(hostname.host)) {
if (hostname.host) {
let hostnameName = hostname.name
// ipv6 host
if (hostnameName.includes(':')) {
hostnameName = `[${hostnameName}]`
}
local.push(`${protocol}://${hostnameName}:${port}${base}`)
const address = `${protocol}://${hostnameName}:${port}${base}`
if (loopbackHosts.has(hostname.host)) {
local.push(address)
} else {
network.push(address)
}
} else {
Object.values(os.networkInterfaces())
.flatMap((nInterface) => nInterface ?? [])
Expand Down

0 comments on commit 20b0cae

Please sign in to comment.