Änderung: Anpassung der Umgebungsvariablen-Lademechanik in loadEnv.js
Änderungen: - Einführung einer Logik zur Priorisierung des Ladens der Produktions-.env-Datei, falls vorhanden, andernfalls wird die lokale .env-Datei verwendet. - Hinzufügung von Protokollausgaben, um anzuzeigen, welche .env-Datei geladen wird. Diese Anpassungen verbessern die Flexibilität beim Laden von Umgebungsvariablen und erleichtern die Konfiguration in verschiedenen Umgebungen.
This commit is contained in:
@@ -2,12 +2,22 @@
|
|||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
|
import fs from 'fs';
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url);
|
const __filename = fileURLToPath(import.meta.url);
|
||||||
const __dirname = path.dirname(__filename);
|
const __dirname = path.dirname(__filename);
|
||||||
|
|
||||||
// Resolve backend/.env regardless of cwd
|
// Versuche zuerst Produktions-.env, dann lokale .env
|
||||||
const envPath = path.resolve(__dirname, '../.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
|
// Lade .env-Datei
|
||||||
const result = dotenv.config({ path: envPath });
|
const result = dotenv.config({ path: envPath });
|
||||||
|
|||||||
Reference in New Issue
Block a user