fix: reuse local gateway port during development
This commit is contained in:
+14
-1
@@ -23,9 +23,22 @@ const gatewayEnvPath = process.env.CREATORHUB_BROWSER_GATEWAY_ENV
|
||||
?? path.join(os.homedir(), ".config", "creatorhub", "browser-gateway.env");
|
||||
const gatewayEnv = readEnvFile(gatewayEnvPath);
|
||||
const env = { ...process.env, ...rootEnv, ...gatewayEnv };
|
||||
if (!env.LISTEN_ADDR) env.LISTEN_ADDR = "0.0.0.0:8081";
|
||||
if (!env.LISTEN_ADDR) env.LISTEN_ADDR = "127.0.0.1:28187";
|
||||
if (!env.GATEWAY_TOKEN) env.GATEWAY_TOKEN = "dev-creatorhub-gateway-token";
|
||||
|
||||
const port = env.LISTEN_ADDR.match(/:(\d+)$/)?.[1] ?? "28187";
|
||||
try {
|
||||
const response = await fetch(`http://127.0.0.1:${port}/healthz`, {
|
||||
signal: AbortSignal.timeout(1000),
|
||||
});
|
||||
if (response.status === 204 || response.ok) {
|
||||
console.log(`[dev-gateway] 已有 gateway 运行于 127.0.0.1:${port},直接复用。`);
|
||||
process.exit(0);
|
||||
}
|
||||
} catch {
|
||||
// The port is available or belongs to a different service; let the gateway report that clearly.
|
||||
}
|
||||
|
||||
const gateway = spawn("python3", ["-m", "browser_gateway.server.http"], {
|
||||
cwd: root,
|
||||
env,
|
||||
|
||||
Reference in New Issue
Block a user