Skip to content

Commit bd07e9e

Browse files
committed
Support both string and integer based IP versions
1 parent a766dd5 commit bd07e9e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,21 @@ function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevS
345345

346346
const configHmrHost = typeof config.server.hmr === 'object' ? config.server.hmr.host : null
347347
const configHost = typeof config.server.host === 'string' ? config.server.host : null
348-
const serverAddress = address.family === 'IPv6' ? `[${address.address}]` : address.address
348+
const serverAddress = isIpv6(address) ? `[${address.address}]` : address.address
349349
const host = configHmrHost ?? configHost ?? serverAddress
350350

351351
return `${protocol}://${host}:${address.port}`
352352
}
353353

354+
function isIpv6(address: AddressInfo): boolean {
355+
return address.family === 'IPv6'
356+
// In node >=18.0 <18.4 this was an integer value. This was changed in a minor version.
357+
// See: https://github.com/laravel/vite-plugin/issues/103
358+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
359+
// @ts-ignore-next-line
360+
|| address.family === 6;
361+
}
362+
354363
/**
355364
* Add the Inertia helpers to the list of SSR dependencies that aren't externalized.
356365
*

0 commit comments

Comments
 (0)