fix: make local database startup self contained
This commit is contained in:
+11
-9
@@ -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";
|
||||
|
||||
@@ -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