fix: make local database startup self contained
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -90,7 +90,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/浏览器生命周期 |
|
||||
| PostgreSQL | `127.0.0.1:5432` | 仅数据库依赖使用容器 |
|
||||
| PostgreSQL | `127.0.0.1:15433`(可由 `CREATORHUB_POSTGRES_PORT` 覆盖) | 仅数据库依赖使用容器 |
|
||||
|
||||
开发默认登录信息和目录可在 `.env.example`、`deploy/browser-gateway.env.example` 中查看。不要把真实密码、Cookie、验证码或令牌写入仓库。
|
||||
|
||||
|
||||
+1
-1
@@ -8,4 +8,4 @@ services:
|
||||
|
||||
postgres:
|
||||
ports:
|
||||
- "5432:5432"
|
||||
- "${CREATORHUB_POSTGRES_PORT:-15433}:5432"
|
||||
|
||||
+1
-1
@@ -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` 覆盖) |
|
||||
|
||||
## 首次配置与生命周期
|
||||
|
||||
|
||||
+1
-1
@@ -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"
|
||||
|
||||
@@ -8,17 +8,16 @@ 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 = {};
|
||||
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";
|
||||
if (!overrides.CONTROL_PLANE_PASSWORD) overrides.CONTROL_PLANE_PASSWORD = "admin123";
|
||||
@@ -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";
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user