Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.5.x] Support both string and integer based IP versions #108

Merged
merged 1 commit into from
Jul 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down