Skip to content

Commit

Permalink
Back-end: Added support default entry to the server config file
Browse files Browse the repository at this point in the history
The server now handles "default" key with entries of default settings. Settings of the specific environment should be prioritize higher.

#217
  • Loading branch information
OrAbramovich committed Mar 30, 2018
1 parent 3dae8e5 commit d7eb4c5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions server/server-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,31 @@ const serverConfig = require('./server-config.json');

const env = process.env.NODE_ENV || 'development';

const setEnvironmentVariables = () => {
const envConfig = serverConfig[env];

const setEnvironmentVariablesByEnv = (enviro) => {
const envConfig = serverConfig[enviro];
Object.keys(envConfig).forEach((key) => {
process.env[key] = envConfig[key];
});
};

const setEnvironmentVariables = () => {
setEnvironmentVariablesByEnv(env);
};

const setDefaultEnvironmentVariables = () => {
setEnvironmentVariablesByEnv('default');
};


setDefaultEnvironmentVariables();

if (env === 'development' || env === 'test') {
setEnvironmentVariables();
}

console.log(`Enviroment: ${colors.green(env)}`);
console.log(`Port: ${colors.green(process.env.PORT)}`);
console.log(`Database: ${colors.green(process.env.MONGODB_URI)}`);
console.log(`Log Level: ${colors.green(process.env.LOG_LEVEL)}`);
console.log('');

0 comments on commit d7eb4c5

Please sign in to comment.