fix: resolve duplicate path and fs declarations and implement smart .env multi-path resolution

This commit is contained in:
Hamza-Ayed
2026-05-18 18:32:31 +03:00
parent 6882d6e952
commit b3ef0b89f6
2 changed files with 24 additions and 17 deletions

View File

@@ -16,13 +16,33 @@ const app = express();
const server = http.createServer(app);
const wss = new WebSocketServer({ server });
// Load environment variables from .env file
require('dotenv').config();
// Load environment variables from .env file (Smart Multi-Path Lookup)
const path = require('path');
const fs = require('fs');
const dotenv = require('dotenv');
const envPaths = [
path.join(__dirname, '.env'), // whatsapp_bridge/.env
path.join(__dirname, '..', '.env'), // mywhatsapp.intaleqapp.com/.env
'/home/intaleqapp-mywhatsapp/.env' // Server user root-level .env (as in user screenshot)
];
let envLoaded = false;
for (const envPath of envPaths) {
if (fs.existsSync(envPath)) {
dotenv.config({ path: envPath });
console.log(`[ENV] Successfully loaded environment variables from: ${envPath}`);
envLoaded = true;
break;
}
}
if (!envLoaded) {
dotenv.config(); // Fallback to default CWD
console.log('[ENV] No specific .env found in known paths, loaded default configuration');
}
// ─── Firebase Admin SDK Configuration (Highly Secure Background Pushes) ─────
const admin = require('firebase-admin');
const path = require('path');
const fs = require('fs');
let firebaseApp = null;