mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-24 15:38:09 +02:00
debug: add database connection diagnostics
This commit is contained in:
1 parent
7a1843e454
commit
ae564b5c46
1 file changed
+18
-1
+18
-1
@@ -6,17 +6,34 @@ import path from "path";
|
|||||||
|
|
||||||
let connectionString = process.env.DATABASE_URL;
|
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
|
// On tente de lire la config sauvegardée via l'UI
|
||||||
try {
|
try {
|
||||||
const CONFIG_PATH = path.join(process.cwd(), "data", ".db-config.json");
|
const CONFIG_PATH = path.join(process.cwd(), "data", ".db-config.json");
|
||||||
if (fs.existsSync(CONFIG_PATH)) {
|
if (fs.existsSync(CONFIG_PATH)) {
|
||||||
|
console.log("[DB] Found config file at:", CONFIG_PATH);
|
||||||
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
|
const config = JSON.parse(fs.readFileSync(CONFIG_PATH, "utf-8"));
|
||||||
if (config.url) {
|
if (config.url) {
|
||||||
connectionString = 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) {
|
} 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({
|
const pool = new Pool({
|
||||||
|
|||||||
Reference in new issue
Block a user