Skip to content

Commit

Permalink
Updated environment detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kadraman committed May 9, 2024
1 parent 1ba60a4 commit 78b9788
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions mongodb/populateDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down
6 changes: 4 additions & 2 deletions src/configs/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,24 @@ 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';
private dbPort: number = config.get('App.dbConfig.port') || 27017;
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}`
);

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);
Expand Down

0 comments on commit 78b9788

Please sign in to comment.