fix: default to 0.0.0.0 to fix WSL2 health check failure (#520)
PR #470 changed the default listen host to undefined, letting Node.js bind to IPv6 :: on systems that support it. This broke WSL2 where IPv6 dual-stack is unreliable — the server binds to :: but IPv4 127.0.0.1 connections fail, causing the health check to time out. Revert to 0.0.0.0 as the default. Users who need IPv6 can set BIND_HOST=:: explicitly. Fixes #518 Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -120,6 +120,15 @@ interface ManagedGateway {
|
||||
process?: ChildProcess
|
||||
}
|
||||
|
||||
function formatHostForUrl(host: string): string {
|
||||
if (host.startsWith('[') && host.endsWith(']')) return host
|
||||
return host.includes(':') ? `[${host}]` : host
|
||||
}
|
||||
|
||||
function buildHttpUrl(host: string, port: number): string {
|
||||
return `http://${formatHostForUrl(host)}:${port}`
|
||||
}
|
||||
|
||||
// ============================
|
||||
// GatewayManager
|
||||
// ============================
|
||||
@@ -360,7 +369,7 @@ export class GatewayManager {
|
||||
const gw = this.gateways.get(name)
|
||||
if (gw?.url) return gw.url
|
||||
const { port, host } = this.readProfilePort(name)
|
||||
return `http://${host}:${port}`
|
||||
return buildHttpUrl(host, port)
|
||||
}
|
||||
|
||||
/** 读取 profile 的 API_SERVER_KEY(从 .env 文件) */
|
||||
@@ -426,7 +435,7 @@ export class GatewayManager {
|
||||
async detectStatus(name: string): Promise<GatewayStatus> {
|
||||
const pid = this.readPidFile(name)
|
||||
const { port, host } = this.readProfilePort(name)
|
||||
const url = `http://${host}:${port}`
|
||||
const url = buildHttpUrl(host, port)
|
||||
|
||||
if (pid && this.isProcessAlive(pid) && await this.checkHealth(url)) {
|
||||
this.gateways.set(name, { pid, port, host, url })
|
||||
@@ -456,7 +465,7 @@ export class GatewayManager {
|
||||
async start(name: string): Promise<GatewayStatus> {
|
||||
const { port, host } = await this.resolvePort(name)
|
||||
const hermesHome = this.profileDir(name)
|
||||
const url = `http://${host}:${port}`
|
||||
const url = buildHttpUrl(host, port)
|
||||
|
||||
if (needsRunMode) {
|
||||
// WSL / Docker:无 systemd/launchd,用 "gateway run" 作为 detached 子进程
|
||||
@@ -534,7 +543,7 @@ export class GatewayManager {
|
||||
const gw = this.gateways.get(name)
|
||||
const url = gw?.url || (() => {
|
||||
const { port, host } = this.readProfilePort(name)
|
||||
return `http://${host}:${port}`
|
||||
return buildHttpUrl(host, port)
|
||||
})()
|
||||
|
||||
if (!needsRunMode) {
|
||||
|
||||
Reference in New Issue
Block a user