fix: reserve web ui port for gateways (#746)

This commit is contained in:
ekko
2026-05-15 12:52:45 +08:00
committed by GitHub
parent 876aa9ee83
commit f6a6c1c228
2 changed files with 25 additions and 0 deletions
@@ -49,6 +49,7 @@ const execFileAsync = promisify(execFile)
const HERMES_BASE = detectHermesHome()
const HERMES_BIN = getHermesBin()
const DEFAULT_WEB_UI_PORT = 8648
/**
* 检测系统的 init 系统(服务管理器)
@@ -174,6 +175,11 @@ export function buildGatewayProcessEnv(profileName: string, hermesHome: string):
}
}
function getWebUiPort(): number | null {
const port = parseInt(process.env.PORT || String(DEFAULT_WEB_UI_PORT), 10)
return port > 0 && port <= 65535 ? port : null
}
// ============================
// 类型定义
// ============================
@@ -472,6 +478,8 @@ export class GatewayManager {
usedPorts.add(gw.port)
}
}
const webUiPort = getWebUiPort()
if (webUiPort !== null) usedPorts.add(webUiPort)
const port = await this.findFreePort(8642, host, usedPorts)
if (configuredPort !== port) {