Skip to content

Commit

Permalink
Merge pull request #108 from timacdonald/ip-as-int
Browse files Browse the repository at this point in the history
[0.5.x] Support both string and integer based IP versions
  • Loading branch information
jessarcher authored Jul 26, 2022
2 parents 338c245 + bd07e9e commit bac9cbe
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ 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

const configHmrClientPort = typeof config.server.hmr === 'object' ? config.server.hmr.clientPort : null
Expand All @@ -348,6 +348,15 @@ function resolveDevServerUrl(address: AddressInfo, config: ResolvedConfig): DevS
return `${protocol}://${host}:${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.
*
Expand Down

0 comments on commit bac9cbe

Please sign in to comment.