From bd07e9e0524e86b44a32b3b0d4ec502768010891 Mon Sep 17 00:00:00 2001 From: Tim MacDonald Date: Mon, 25 Jul 2022 11:05:37 +1000 Subject: [PATCH] Support both string and integer based IP versions --- src/index.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index 78c646b..bf9e7a6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -345,12 +345,21 @@ function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevS const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null const configHost = typeof config.server.host === 'string' ? config.server.host : null - const serverAddress = address.family === 'IPv6' ? `[${address.address}]` : address.address + const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address const host = configHmrHost ?? configHost ?? serverAddress return `${protocol}://${host}:${address.port}` } +function isIpv6(address: AddressInfo): boolean { + return address.family === 'IPv6' + // In node >=18.0 <18.4 this was an integer value. This was changed in a minor version. + // See: https://github.com/laravel/vite-plugin/issues/103 + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore-next-line + || address.family === 6; +} + /** * Add the Inertia helpers to the list of SSR dependencies that aren't externalized. *