fix: resolve duplicate path and fs declarations and implement smart .env multi-path resolution
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user