From 29c797c7dd6d9039960516998859ace9f8ffd7a8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <michael@minelli.me>
Date: Thu, 21 Sep 2023 16:15:49 +0200
Subject: [PATCH] App => Load env file for dev or prod

---
 ExpressAPI/src/app.ts | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ExpressAPI/src/app.ts b/ExpressAPI/src/app.ts
index df00fc0..1250af3 100644
--- a/ExpressAPI/src/app.ts
+++ b/ExpressAPI/src/app.ts
@@ -1,5 +1,15 @@
-require('dotenv').config(); // ATTENTION : This line MUST be the first of this file
-require('./shared/helpers/TypeScriptExtensions'); // ATTENTION : This line MUST be the second of this file
+// Read from the .env file
+// ATTENTION : This lines MUST be the first of this file (except for the path import)
+const path = require('node:path');
+
+if ( process.env.NODE_ENV && process.env.NODE_ENV === 'production' ) {
+    require('dotenv').config();
+} else {
+    require('dotenv').config({ path: path.join(__dirname, '../.env.keys') });
+    require('dotenv').config({ DOTENV_KEY: process.env.DOTENV_KEY_DEVELOPMENT });
+}
+
+require('./shared/helpers/TypeScriptExtensions'); // ATTENTION : This line MUST be after the dotenv.config() calls
 
 import WorkerRole     from './process/WorkerRole';
 import ClusterManager from './process/ClusterManager';
-- 
GitLab