diff --git a/.env.example b/.env.example index ae86db1..17407ec 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/README.md b/README.md index 92bd7c0..1fed2e2 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ pnpm frontend # Vite 前端,支持 HMR | --- | --- | --- | | 前端 | | `/api` 代理到本地 control-plane | | control-plane | | Go 热加载 | -| native browser gateway | | 宿主机 Xvfb/浏览器生命周期 | +| native browser gateway | | 宿主机 Xvfb/浏览器生命周期 | | PostgreSQL | `127.0.0.1:15433`(可由 `CREATORHUB_POSTGRES_PORT` 覆盖) | 仅数据库依赖使用容器 | 开发默认登录信息和目录可在 `.env.example`、`deploy/browser-gateway.env.example` 中查看。不要把真实密码、Cookie、验证码或令牌写入仓库。 diff --git a/docs/deployment.md b/docs/deployment.md index 599bfe4..21822b5 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -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` 覆盖) | ## 首次配置与生命周期 diff --git a/scripts/dev-backend.mjs b/scripts/dev-backend.mjs index 1ab46c3..5d860b1 100755 --- a/scripts/dev-backend.mjs +++ b/scripts/dev-backend.mjs @@ -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)], { diff --git a/scripts/dev-gateway.mjs b/scripts/dev-gateway.mjs index 7aa8bac..654a5a9 100644 --- a/scripts/dev-gateway.mjs +++ b/scripts/dev-gateway.mjs @@ -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,