Update: 2026-07-06 17:05:27
This commit is contained in:
@@ -1,8 +1,28 @@
|
||||
import mysql, { RowDataPacket, ResultSetHeader } from 'mysql2/promise';
|
||||
import dotenv from 'dotenv';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
|
||||
dotenv.config({ path: path.resolve(__dirname, '../../.env') });
|
||||
// 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);
|
||||
|
||||
let envLoaded = false;
|
||||
for (const envPath of possibleEnvPaths) {
|
||||
if (fs.existsSync(envPath)) {
|
||||
dotenv.config({ path: envPath });
|
||||
console.log(`Loaded environment from: ${envPath}`);
|
||||
envLoaded = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!envLoaded) {
|
||||
console.warn('⚠️ No .env file found. Falling back to default environment variables.');
|
||||
}
|
||||
|
||||
let mysqlPool: mysql.Pool | null = null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user