From 20b0caef6379aac9185c92e88e69e2f11d4d04e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sat, 3 Jun 2023 22:11:40 +0900 Subject: [PATCH] fix: only show the listened IP when host is specified (#13412) --- packages/vite/src/node/utils.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 990cc6aad92cb3..026c5abc370f43 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -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 ?? [])