From 78b9788f2650076f34f90d95fc2037c4994da3ba Mon Sep 17 00:00:00 2001 From: kadraman Date: Thu, 9 May 2024 08:52:23 +0100 Subject: [PATCH] Updated environment detection --- mongodb/populateDb.js | 5 +++-- src/configs/app.config.ts | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mongodb/populateDb.js b/mongodb/populateDb.js index ff4c632..9d64c1c 100644 --- a/mongodb/populateDb.js +++ b/mongodb/populateDb.js @@ -4,13 +4,14 @@ const userArgs = process.argv.slice(2); const config = require('config'); +const curEnv = config.util.getEnv('NODE_ENV'); +console.log(`[INFO]:: Running in environment: ${curEnv}`); const dbHost = config.get('App.dbConfig.host') || 'localhost'; const dbPort = config.get('App.dbConfig.port') || 27017; const dbName = config.get('App.dbConfig.database') || 'iwa'; const dbUser = config.get('App.dbConfig.user') || 'iwa'; const dbPassword = config.get('App.dbConfig.password') || 'iwa'; -console.log(`[INFO]:: Running in environment: ${config.util.getEnv()}`); -if (config.util.getEnv() == "production") { +if (curEnv == "production") { mongoDB = `mongodb://${dbUser}:${dbPassword}@${dbHost}:${dbPort}/${dbName}?authSource=admin`; } else { mongoDB = `mongodb://${dbHost}:${dbPort}/${dbName}`; diff --git a/src/configs/app.config.ts b/src/configs/app.config.ts index 60c2add..a714300 100644 --- a/src/configs/app.config.ts +++ b/src/configs/app.config.ts @@ -44,7 +44,8 @@ require('dotenv').config(); class AppConfig { public app: express.Application; - + + private curEnv: string = config.util.getEnv('NODE_ENV'); public apiVersion: string = config.get('App.apiConfig.version') || 'v1'; public privateKey: string = '-----BEGIN RSA PRIVATE KEY-----\r\nMIICXAIBAAKBgQDNwqLEe9wgTXCbC7+RPdDbBbeqjdbs4kOPOIGzqLpXvJXlxxW8iMz0EaM4BKUqYsIa+ndv3NAn2RxCd5ubVdJJcX43zO6Ko0TFEZx/65gY3BE0O6syCEmUP4qbSd6exou/F+WTISzbQ5FBVPVmhnYhG/kpwt/cIxK5iUn5hm+4tQIDAQABAoGBAI+8xiPoOrA+KMnG/T4jJsG6TsHQcDHvJi7o1IKC/hnIXha0atTX5AUkRRce95qSfvKFweXdJXSQ0JMGJyfuXgU6dI0TcseFRfewXAa/ssxAC+iUVR6KUMh1PE2wXLitfeI6JLvVtrBYswm2I7CtY0q8n5AGimHWVXJPLfGV7m0BAkEA+fqFt2LXbLtyg6wZyxMA/cnmt5Nt3U2dAu77MzFJvibANUNHE4HPLZxjGNXN+a6m0K6TD4kDdh5HfUYLWWRBYQJBANK3carmulBwqzcDBjsJ0YrIONBpCAsXxk8idXb8jL9aNIg15Wumm2enqqObahDHB5jnGOLmbasizvSVqypfM9UCQCQl8xIqy+YgURXzXCN+kwUgHinrutZms87Jyi+D8Br8NY0+Nlf+zHvXAomD2W5CsEK7C+8SLBr3k/TsnRWHJuECQHFE9RA2OP8WoaLPuGCyFXaxzICThSRZYluVnWkZtxsBhW2W8z1b8PvWUE7kMy7TnkzeJS2LSnaNHoyxi7IaPQUCQCwWU4U+v4lD7uYBw00Ga/xt+7+UqFPlPVdz1yyr4q24Zxaw0LgmuEvgU5dycq8N7JxjTubX0MIRR+G9fmDBBl8=\r\n-----END RSA PRIVATE KEY-----' private dbHost: string = config.get('App.dbConfig.host') || 'localhost'; @@ -52,7 +53,7 @@ class AppConfig { private dbName: string = config.get('App.dbConfig.database') || 'iwa'; private dbUser: string = config.get('App.dbConfig.user') || 'iwa'; private dbPassword: string = config.get('App.dbConfig.password') || 'iwa'; - public mongoUrl: string = (config.util.getEnv('NODE_ENV') == "production" + public mongoUrl: string = (this.curEnv == "production" ? `mongodb://${this.dbUser}:${this.dbPassword}@${this.dbHost}:${this.dbPort}/${this.dbName}?authSource=admin` : `mongodb://${this.dbHost}:${this.dbPort}/${this.dbName}` ); @@ -60,6 +61,7 @@ class AppConfig { constructor() { this.app = express(); this.config(); + Logger.debug(`Running in environment: ${this.curEnv}`) this.mongoSetup().then(r => Logger.debug(`Connected to ${this.mongoUrl}`)); this.app.use(siteRoutes);