fix: reuse local gateway port during development
This commit is contained in:
+1
-1
@@ -1,7 +1,7 @@
|
||||
CREATORHUB_PORT=8082
|
||||
CREATORHUB_POSTGRES_PORT=15433
|
||||
DATABASE_URL=postgres://creatorhub@127.0.0.1:15433/creatorhub?sslmode=disable
|
||||
NATIVE_GATEWAY_ENDPOINT=http://127.0.0.1:8081
|
||||
NATIVE_GATEWAY_ENDPOINT=http://127.0.0.1:28187
|
||||
GATEWAY_TOKEN=dev-creatorhub-gateway-token
|
||||
BROWSER_STATE_DIR=~/.local/state/creatorhub/browser-gateway
|
||||
BROWSER_PROFILE_ROOT=~/.local/share/creatorhub/browser-profiles
|
||||
|
||||
@@ -89,7 +89,7 @@ pnpm frontend # Vite 前端,支持 HMR
|
||||
| --- | --- | --- |
|
||||
| 前端 | <http://127.0.0.1:5173> | `/api` 代理到本地 control-plane |
|
||||
| control-plane | <http://127.0.0.1:8082> | Go 热加载 |
|
||||
| native browser gateway | <http://127.0.0.1:8081> | 宿主机 Xvfb/浏览器生命周期 |
|
||||
| native browser gateway | <http://127.0.0.1:28187> | 宿主机 Xvfb/浏览器生命周期 |
|
||||
| PostgreSQL | `127.0.0.1:15433`(可由 `CREATORHUB_POSTGRES_PORT` 覆盖) | 仅数据库依赖使用容器 |
|
||||
|
||||
开发默认登录信息和目录可在 `.env.example`、`deploy/browser-gateway.env.example` 中查看。不要把真实密码、Cookie、验证码或令牌写入仓库。
|
||||
|
||||
+1
-1
@@ -116,7 +116,7 @@ pnpm frontend # Vite,HMR
|
||||
| --- | --- |
|
||||
| Vite | `http://127.0.0.1:5173` |
|
||||
| control-plane | `http://0.0.0.0:8082` |
|
||||
| native gateway | `http://0.0.0.0:8081` |
|
||||
| native gateway | `http://127.0.0.1:28187` |
|
||||
| PostgreSQL | `127.0.0.1:15433`(可由 `CREATORHUB_POSTGRES_PORT` 覆盖) |
|
||||
|
||||
## 首次配置与生命周期
|
||||
|
||||
@@ -36,7 +36,7 @@ if (!overrides.DATABASE_URL) {
|
||||
if (!overrides.CREATORHUB_CREDENTIAL_STORE_DIR) overrides.CREATORHUB_CREDENTIAL_STORE_DIR = path.join(root, ".dev-credentials");
|
||||
if (!overrides.WEB_DIR) overrides.WEB_DIR = path.join(root, "web", "dist");
|
||||
if (!overrides.LOG_LEVEL) overrides.LOG_LEVEL = "debug";
|
||||
if (!overrides.NATIVE_GATEWAY_ENDPOINT) overrides.NATIVE_GATEWAY_ENDPOINT = "http://127.0.0.1:8081";
|
||||
if (!overrides.NATIVE_GATEWAY_ENDPOINT) overrides.NATIVE_GATEWAY_ENDPOINT = "http://127.0.0.1:28187";
|
||||
|
||||
const env = { ...process.env, ...overrides };
|
||||
const air = spawn("air", ["-c", ".air.toml", ...process.argv.slice(2)], {
|
||||
|
||||
+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