Update: 2026-07-06 17:13:49
This commit is contained in:
@@ -3,16 +3,26 @@ import dotenv from 'dotenv';
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
|
||||||
// Find the correct .env file (mimicking PHP bootstrap.php logic)
|
// مسارات ثابتة ومحددة بدقة لمنع الوقوع في فخاخ ملفات .env الوهمية
|
||||||
const possibleEnvPaths = [
|
const possibleEnvPaths: string[] = [
|
||||||
path.resolve(__dirname, '../../../.env'), // backend/.env
|
// مسار السيرفر الفعلي حسب الصورة
|
||||||
path.resolve(__dirname, '../../../../.env'), // root/.env
|
'/home/intaleqapp-jordan-siro/.env',
|
||||||
process.env.HOME ? path.resolve(process.env.HOME, '.env') : '', // /home/user/.env
|
|
||||||
].filter(Boolean);
|
// مسارات احتياطية للبيئة المحلية (جهاز الماك الخاص بك)
|
||||||
|
path.resolve(__dirname, '../../../.env'),
|
||||||
|
path.resolve(__dirname, '../../../../.env')
|
||||||
|
];
|
||||||
|
|
||||||
let envLoaded = false;
|
let envLoaded = false;
|
||||||
for (const envPath of possibleEnvPaths) {
|
for (const envPath of possibleEnvPaths) {
|
||||||
if (fs.existsSync(envPath)) {
|
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 });
|
dotenv.config({ path: envPath });
|
||||||
console.log(`Loaded environment from: ${envPath}`);
|
console.log(`Loaded environment from: ${envPath}`);
|
||||||
envLoaded = true;
|
envLoaded = true;
|
||||||
@@ -21,7 +31,7 @@ for (const envPath of possibleEnvPaths) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!envLoaded) {
|
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;
|
let mysqlPool: mysql.Pool | null = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user