debug: add database connection diagnostics

This commit is contained in:
Michael committed 2026-02-21 13:12:11 +01:00
1 parent 7a1843e454
commit ae564b5c46
1 file changed
+18 -1
+18 -1
View File
@@ -6,17 +6,34 @@ import path from "path";
let connectionString = process.env.DATABASE_URL;
function maskUrl(url: string | undefined) {
if (!url) return "undefined";
return url.replace(/:([^@]+)@/, ":****@");
}
console.log("[DB] Initial DATABASE_URL (env):", maskUrl(connectionString));
// On tente de lire la config sauvegardée via l'UI
try {
const CONFIG_PATH = path.join(process.cwd(), "data", ".db-config.json");
if (fs.existsSync(CONFIG_PATH)) {
console.log("[DB] Found config file at:", CONFIG_PATH);
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
if (config.url) {
connectionString = config.url;
console.log("[DB] Using saved database URL:", maskUrl(connectionString));
} else {
console.warn("[DB] Config file found but no 'url' key present.");
}
} else {
console.log("[DB] No saved config file found at:", CONFIG_PATH, "(Falling back to env)");
}
} catch (err) {
console.error("Error reading database config file:", err);
console.error("[DB] Error reading database config file:", err);
}
if (!connectionString) {
console.error("[DB] CRITICAL: No database connection string available!");
}
const pool = new Pool({