diff --git a/backend/pricing-engine/src/db/connection.ts b/backend/pricing-engine/src/db/connection.ts index 57b88528..4bcbd616 100644 --- a/backend/pricing-engine/src/db/connection.ts +++ b/backend/pricing-engine/src/db/connection.ts @@ -3,16 +3,26 @@ import dotenv from 'dotenv'; import path from 'path'; import fs from 'fs'; -// Find the correct .env file (mimicking PHP bootstrap.php logic) -const possibleEnvPaths = [ - path.resolve(__dirname, '../../../.env'), // backend/.env - path.resolve(__dirname, '../../../../.env'), // root/.env - process.env.HOME ? path.resolve(process.env.HOME, '.env') : '', // /home/user/.env -].filter(Boolean); +// مسارات ثابتة ومحددة بدقة لمنع الوقوع في فخاخ ملفات .env الوهمية +const possibleEnvPaths: string[] = [ + // مسار السيرفر الفعلي حسب الصورة + '/home/intaleqapp-jordan-siro/.env', + + // مسارات احتياطية للبيئة المحلية (جهاز الماك الخاص بك) + path.resolve(__dirname, '../../../.env'), + path.resolve(__dirname, '../../../../.env') +]; let envLoaded = false; for (const envPath of possibleEnvPaths) { if (fs.existsSync(envPath)) { + // Basic check to ensure we don't load a dummy Docker env file + const content = fs.readFileSync(envPath, 'utf8'); + if (content.includes('DB_HOST=db')) { + console.log(`Skipping trap file: ${envPath}`); + continue; + } + dotenv.config({ path: envPath }); console.log(`Loaded environment from: ${envPath}`); envLoaded = true; @@ -21,7 +31,7 @@ for (const envPath of possibleEnvPaths) { } if (!envLoaded) { - console.warn('⚠️ No .env file found. Falling back to default environment variables.'); + console.warn('⚠️ No .env file found in the specified exact paths. Falling back to default environment variables.'); } let mysqlPool: mysql.Pool | null = null;