fix(dev): avoid localhost dual-stack collisions
This commit is contained in:
@@ -381,6 +381,9 @@ export class CliProcessManager extends EventEmitter {
|
|||||||
if (options.dev) {
|
if (options.dev) {
|
||||||
// Dev: run plain HTTP + Vite dev server proxy.
|
// Dev: run plain HTTP + Vite dev server proxy.
|
||||||
args.push("--https", "false", "--http", "true")
|
args.push("--https", "false", "--http", "true")
|
||||||
|
// Avoid collisions with an already-running server (and dual-stack ::/0.0.0.0 quirks)
|
||||||
|
// by forcing an ephemeral port in dev.
|
||||||
|
args.push("--http-port", "0")
|
||||||
} else {
|
} else {
|
||||||
// Prod desktop: always keep loopback HTTP enabled.
|
// Prod desktop: always keep loopback HTTP enabled.
|
||||||
args.push("--https", "true", "--http", "true")
|
args.push("--https", "true", "--http", "true")
|
||||||
|
|||||||
@@ -423,7 +423,11 @@ async function main() {
|
|||||||
const localProtocol: "http" | "https" = httpStart ? "http" : "https"
|
const localProtocol: "http" | "https" = httpStart ? "http" : "https"
|
||||||
const remoteProtocol: "http" | "https" = httpsStart ? "https" : "http"
|
const remoteProtocol: "http" | "https" = httpsStart ? "https" : "http"
|
||||||
|
|
||||||
const localUrl = `${localProtocol}://localhost:${localStart.port}`
|
// Use an explicit IPv4 loopback address for the "local" URL.
|
||||||
|
// On macOS, `localhost` often resolves to ::1 first, and it is possible to have
|
||||||
|
// another instance bound on IPv6 while this instance binds IPv4 (or vice versa),
|
||||||
|
// which can lead clients to talk to the wrong process.
|
||||||
|
const localUrl = `${localProtocol}://127.0.0.1:${localStart.port}`
|
||||||
let remoteUrl: string | undefined
|
let remoteUrl: string | undefined
|
||||||
if (remoteStart) {
|
if (remoteStart) {
|
||||||
const wantsAll = options.host === "0.0.0.0" || !isLoopbackHost(options.host)
|
const wantsAll = options.host === "0.0.0.0" || !isLoopbackHost(options.host)
|
||||||
|
|||||||
Reference in New Issue
Block a user