Änderungen: - Hinzufügung von Protokollausgaben zur Bestätigung des erfolgreichen Ladens der .env-Datei. - Erweiterte Debug-Ausgaben zur Anzeige der Redis-Konfiguration, einschließlich Host, Port, Passwort und URL. Diese Anpassungen verbessern die Transparenz beim Laden von Umgebungsvariablen und erleichtern die Fehlersuche bei der Redis-Konfiguration.
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
// Centralized environment loader
|
|
import path from 'path';
|
|
import { fileURLToPath } from 'url';
|
|
import dotenv from 'dotenv';
|
|
import fs from 'fs';
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
// Versuche zuerst Produktions-.env, dann lokale .env
|
|
const productionEnvPath = '/opt/yourpart/backend/.env';
|
|
const localEnvPath = path.resolve(__dirname, '../.env');
|
|
|
|
let envPath = localEnvPath; // Fallback
|
|
if (fs.existsSync(productionEnvPath)) {
|
|
envPath = productionEnvPath;
|
|
console.log('[env] Lade Produktions-.env:', productionEnvPath);
|
|
} else {
|
|
console.log('[env] Lade lokale .env:', localEnvPath);
|
|
}
|
|
|
|
// Lade .env-Datei
|
|
const result = dotenv.config({ path: envPath });
|
|
if (result.error) {
|
|
console.warn('[env] Konnte .env nicht laden:', result.error.message);
|
|
} else {
|
|
console.log('[env] .env erfolgreich geladen von:', envPath);
|
|
}
|
|
|
|
// Debug: Zeige Redis-Konfiguration
|
|
console.log('[env] Redis-Konfiguration:');
|
|
console.log('[env] REDIS_HOST:', process.env.REDIS_HOST);
|
|
console.log('[env] REDIS_PORT:', process.env.REDIS_PORT);
|
|
console.log('[env] REDIS_PASSWORD:', process.env.REDIS_PASSWORD ? '***gesetzt***' : 'NICHT GESETZT');
|
|
console.log('[env] REDIS_URL:', process.env.REDIS_URL);
|
|
|
|
if (!process.env.SECRET_KEY) {
|
|
console.warn('[env] SECRET_KEY nicht gesetzt in .env');
|
|
}
|
|
export {};
|