refactor(env): PostgreSQL 설정을 PG_DB_* 변수로 통일(DB_* 레거시 호환 유지)
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
23
server.js
23
server.js
@@ -36,6 +36,13 @@ function parseEmailCsv(s) {
|
||||
return parseCsv(s).map((x) => x.toLowerCase());
|
||||
}
|
||||
|
||||
/** Prefer PG_DB_* env ; fall back to legacy DB_* for migrations. */
|
||||
function pgEnv(primary, legacy, fallback = "") {
|
||||
const v = String(env(primary, "")).trim();
|
||||
if (v) return v;
|
||||
return String(env(legacy, fallback)).trim();
|
||||
}
|
||||
|
||||
/** Prefer `email`; also Auth0-style namespaced claims ending with `/email`. */
|
||||
function emailFromIdTokenPayload(payload) {
|
||||
const e = payload?.email;
|
||||
@@ -50,12 +57,18 @@ function emailFromIdTokenPayload(payload) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function mustPg(primary, legacy) {
|
||||
const v = pgEnv(primary, legacy);
|
||||
if (!v) throw new Error(`Missing env: ${primary}${legacy ? ` or ${legacy}` : ""}`);
|
||||
return v;
|
||||
}
|
||||
|
||||
const PORT = Number(env("PORT", "8000")) || 8000;
|
||||
const DB_HOST = must("DB_HOST");
|
||||
const DB_PORT = Number(env("DB_PORT", "5432")) || 5432;
|
||||
const DB_NAME = must("DB_NAME");
|
||||
const DB_USER = must("DB_USER");
|
||||
const DB_PASSWORD = must("DB_PASSWORD");
|
||||
const DB_HOST = mustPg("PG_DB_HOST", "DB_HOST");
|
||||
const DB_PORT = Number(pgEnv("PG_DB_PORT", "DB_PORT", "5432")) || 5432;
|
||||
const DB_NAME = mustPg("PG_DB_NAME", "DB_NAME");
|
||||
const DB_USER = mustPg("PG_DB_USER", "DB_USER");
|
||||
const DB_PASSWORD = mustPg("PG_DB_PASSWORD", "DB_PASSWORD");
|
||||
const TABLE = safeIdent(env("TABLE", "ncue_user") || "ncue_user");
|
||||
const CONFIG_TABLE = "ncue_app_config";
|
||||
const CONFIG_TOKEN = env("CONFIG_TOKEN", "").trim();
|
||||
|
||||
Reference in New Issue
Block a user