diff --git a/.env.example b/.env.example index d4ea5db..ae86db1 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,6 @@ 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 GATEWAY_TOKEN=dev-creatorhub-gateway-token BROWSER_STATE_DIR=~/.local/state/creatorhub/browser-gateway diff --git a/README.md b/README.md index 8768a48..92bd7c0 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ pnpm frontend # Vite 前端,支持 HMR | 前端 | | `/api` 代理到本地 control-plane | | control-plane | | Go 热加载 | | native browser gateway | | 宿主机 Xvfb/浏览器生命周期 | -| PostgreSQL | `127.0.0.1:5432` | 仅数据库依赖使用容器 | +| PostgreSQL | `127.0.0.1:15433`(可由 `CREATORHUB_POSTGRES_PORT` 覆盖) | 仅数据库依赖使用容器 | 开发默认登录信息和目录可在 `.env.example`、`deploy/browser-gateway.env.example` 中查看。不要把真实密码、Cookie、验证码或令牌写入仓库。 diff --git a/compose.dev.yaml b/compose.dev.yaml index e598e11..acbaf58 100644 --- a/compose.dev.yaml +++ b/compose.dev.yaml @@ -8,4 +8,4 @@ services: postgres: ports: - - "5432:5432" + - "${CREATORHUB_POSTGRES_PORT:-15433}:5432" diff --git a/docs/deployment.md b/docs/deployment.md index b18b112..599bfe4 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -117,7 +117,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` | -| PostgreSQL | `127.0.0.1:5432` | +| PostgreSQL | `127.0.0.1:15433`(可由 `CREATORHUB_POSTGRES_PORT` 覆盖) | ## 首次配置与生命周期 diff --git a/package.json b/package.json index e32f483..2803a28 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "private": true, "version": "0.1.0", "scripts": { - "db": "docker compose -f compose.yaml -f compose.dev.yaml up -d postgres", + "db": "CONTROL_PLANE_USERNAME=${CONTROL_PLANE_USERNAME:-admin} CONTROL_PLANE_PASSWORD=${CONTROL_PLANE_PASSWORD:-admin123} CREATORHUB_CREDENTIAL_MASTER_KEY=${CREATORHUB_CREDENTIAL_MASTER_KEY:-Y3JlYXRvcmh1YiBkZXYgIGxvY2FsIG1hc3RlciBrZXk=} docker compose -f compose.yaml -f compose.dev.yaml up -d postgres", "backend": "node scripts/dev-backend.mjs", "frontend": "pnpm -C web run dev", "gateway": "node scripts/dev-gateway.mjs" diff --git a/scripts/dev-backend.mjs b/scripts/dev-backend.mjs index 9007c1b..1ab46c3 100755 --- a/scripts/dev-backend.mjs +++ b/scripts/dev-backend.mjs @@ -8,16 +8,15 @@ import path from "node:path"; const root = path.dirname(path.dirname(fileURLToPath(import.meta.url))); const envPath = path.join(root, ".env"); -if (!existsSync(envPath)) { - console.error("缺少 .env:请参照 .env.example 创建(开发值任意填)。"); - process.exit(1); -} - // 简易 KEY=value 解析(与 compose 的 env_file 语法一致,无需处理引号)。 const overrides = {}; -for (const line of readFileSync(envPath, "utf8").split("\n")) { - const m = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(line.trim()); - if (m && !(m[1] in overrides)) overrides[m[1]] = m[2]; +if (existsSync(envPath)) { + for (const line of readFileSync(envPath, "utf8").split("\n")) { + const m = /^([A-Za-z_][A-Za-z0-9_]*)=(.*)$/.exec(line.trim()); + if (m && !(m[1] in overrides)) overrides[m[1]] = m[2]; + } +} else { + console.warn("[dev-backend] 未找到 .env,使用本地开发默认值。"); } if (!overrides.CONTROL_PLANE_USERNAME) overrides.CONTROL_PLANE_USERNAME = "admin"; @@ -30,7 +29,10 @@ if (Buffer.from(overrides.CREATORHUB_CREDENTIAL_MASTER_KEY ?? "", "base64").leng overrides.CREATORHUB_CREDENTIAL_MASTER_KEY = devMasterKey; } if (!overrides.LISTEN_ADDR) overrides.LISTEN_ADDR = ":8082"; -if (!overrides.DATABASE_URL) overrides.DATABASE_URL = "postgres://creatorhub@127.0.0.1:5432/creatorhub?sslmode=disable"; +if (!overrides.DATABASE_URL) { + const postgresPort = overrides.CREATORHUB_POSTGRES_PORT || "15433"; + overrides.DATABASE_URL = `postgres://creatorhub@127.0.0.1:${postgresPort}/creatorhub?sslmode=disable`; +} 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"; diff --git a/scripts/dev-gateway.mjs b/scripts/dev-gateway.mjs index fdc3465..7aa8bac 100644 --- a/scripts/dev-gateway.mjs +++ b/scripts/dev-gateway.mjs @@ -24,6 +24,7 @@ const gatewayEnvPath = process.env.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.GATEWAY_TOKEN) env.GATEWAY_TOKEN = "dev-creatorhub-gateway-token"; const gateway = spawn("python3", ["-m", "browser_gateway.server.http"], { cwd: root,