Skip to content
Snippets Groups Projects
Commit 873a1406 authored by Rudolf Copi Eckelberg's avatar Rudolf Copi Eckelberg
Browse files

Config file style changed

parent bb7f77a5
No related branches found
No related tags found
2 merge requests!116Release v1.0.0,!25Auth
Pipeline #
...@@ -20,4 +20,3 @@ build/* ...@@ -20,4 +20,3 @@ build/*
config.json config.json
docs/ docs/
test_config.json
{
"development":
{
"port": 3000,
"ip": "127.0.0.1",
"debug" : true,
"monetdb": {
"host": "simcaqdb1",
"port": 50000,
"dbname": "simcaq_dev",
"user": "monetdb",
"password":"monetdb",
"nrConnections": "16"
},
"mongodb" : {
"uri": "mongodb://localhost/users"
},
"default": {
"api": {
"version" : "v1"
}
}
},
"test":
{
"port": 3000,
"ip": "127.0.0.1",
"debug" : true,
"monetdb": {
"host": "simcaqdb1",
"port": 50000,
"dbname": "simcaq_dev",
"user": "monetdb",
"password":"monetdb",
"nrConnections": "16"
},
"mongodb" : {
"uri": "mongodb://localhost/test_users"
},
"default": {
"api": {
"version" : "v1"
}
}
},
"production":
{
"port": 3000,
"ip": "127.0.0.1",
"debug" : true,
"monetdb": {
"host": "simcaqdb1",
"port": 50000,
"dbname": "simcaq_dev",
"user": "monetdb",
"password":"monetdb",
"nrConnections": "16"
},
"mongodb" : {
"uri": "mongodb://localhost/users"
},
"default": {
"api": {
"version" : "v1"
}
}
}
}
{
"port": 3000,
"ip": "127.0.0.1",
"debug" : false,
"monetdb": {
"host": "simcaqdb1",
"port": 50000,
"dbname": "simcaq_dev",
"user": "monetdb",
"password":"monetdb",
"nrConnections": "16"
},
"mongodb" : {
"uri": "mongodb://localhost/users"
},
"default": {
"api": {
"version" : "v1"
}
}
}
{
"port": 3000,
"ip": "127.0.0.1",
"debug" : true,
"monetdb": {
"host": "simcaqdb1",
"port": 50000,
"dbname": "simcaq_dev",
"user": "monetdb",
"password":"monetdb",
"nrConnections": "16"
},
"mongodb" : {
"uri": "mongodb://localhost/test_users"
},
"default": {
"api": {
"version" : "v1"
}
}
}
...@@ -46,10 +46,8 @@ gulp.task('compile', () => { ...@@ -46,10 +46,8 @@ gulp.task('compile', () => {
.pipe(gulp.dest('build')); // move compiled files to build directory .pipe(gulp.dest('build')); // move compiled files to build directory
// copy configuration file to build directory // copy configuration file to build directory
gulp.src('config/config.json') gulp.src('config.json')
.pipe(gulp.dest('build/config')); .pipe(gulp.dest('build'));
gulp.src('config/test_config.json')
.pipe(gulp.dest('build/config'));
}); });
gulp.task('build', ['compile']); gulp.task('build', ['compile']);
......
...@@ -12,7 +12,7 @@ const log = require(`${libs}/log`)(module); ...@@ -12,7 +12,7 @@ const log = require(`${libs}/log`)(module);
process.env.NODE_ENV = process.env.NODE_ENV || 'development'; process.env.NODE_ENV = process.env.NODE_ENV || 'development';
const config = require(`${libs}/config`); const config = require(`${libs}/config`);
const cache = require('apicache').options({ debug: config.get('debug') }).middleware; const cache = require('apicache').options({ debug: config.debug }).middleware;
const app = express(); const app = express();
......
const nconf = require('nconf'); let conf = require(`${process.cwd()}/config.json`);
const CONFIG_DIR = `config` conf = conf[process.env.NODE_ENV];
let config_file;
switch(process.env.NODE_ENV) { module.exports = conf;
case 'development':
config_file = `${CONFIG_DIR}/config.json`;
break;
case 'test':
config_file = `${CONFIG_DIR}/test_config.json`;
break;
case 'production':
config_file = `${CONFIG_DIR}/config.json`;
break;
}
// Exports the config.json as an object with get functions
nconf.argv()
.env()
.file({ file: `${process.cwd()}/${config_file}` });
module.exports = nconf;
...@@ -6,16 +6,16 @@ const config = require(`${libs}/config`); ...@@ -6,16 +6,16 @@ const config = require(`${libs}/config`);
// Connection options // Connection options
const poolOptions = { const poolOptions = {
nrConnections: config.get('monetdb:nrConnections'), nrConnections: config.monetdb.nrConnections,
}; };
// Configuration options // Configuration options
const options = { const options = {
host: config.get('monetdb:host'), host: config.monetdb.host,
port: config.get('monetdb:port'), port: config.monetdb.port,
dbname: config.get('monetdb:dbname'), dbname: config.monetdb.dbname,
user: config.get('monetdb:user'), user: config.monetdb.user,
password: config.get('monetdb:password'), password: config.monetdb.password,
}; };
// Connection singleton // Connection singleton
......
...@@ -8,7 +8,7 @@ const mongoose = require('mongoose'); ...@@ -8,7 +8,7 @@ const mongoose = require('mongoose');
module.exports = () => { module.exports = () => {
// Get mongodb URI (ip and port) in config file // Get mongodb URI (ip and port) in config file
const mongoUri = config.get('mongodb:uri'); const mongoUri = config.mongodb.uri;
log.debug(`Connecting to MongDB on URI ${mongoUri}`); log.debug(`Connecting to MongDB on URI ${mongoUri}`);
// Connection singleton // Connection singleton
const db = mongoose.connect(mongoUri); const db = mongoose.connect(mongoUri);
......
...@@ -47,7 +47,7 @@ function logger(module) { ...@@ -47,7 +47,7 @@ function logger(module) {
], ],
exitOnError: false, exitOnError: false,
}); });
if (!config.get('debug')) { if (!config.debug) {
log.remove('debug-log'); log.remove('debug-log');
} }
return log; return log;
......
const mongoose = require('mongoose') const mongoose = require('mongoose')
const libs = `${process.cwd()}/libs`; const libs = `${process.cwd()}/libs`;
const config = require(`${libs}/config`);
const log = require(`${libs}/log`)(module); const log = require(`${libs}/log`)(module);
const Schema = mongoose.Schema; const Schema = mongoose.Schema;
......
...@@ -6,7 +6,6 @@ const libs = `${process.cwd()}/libs`; ...@@ -6,7 +6,6 @@ const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module); const log = require(`${libs}/log`)(module);
const config = require(`${libs}/config`);
const squel = require('squel'); const squel = require('squel');
......
...@@ -9,10 +9,10 @@ const log = require(`${libs}/log`)(module); ...@@ -9,10 +9,10 @@ const log = require(`${libs}/log`)(module);
const app = require(`${libs}/app`); const app = require(`${libs}/app`);
// Set default port: first environment variable PORT, then configuration and last 3000 // Set default port: first environment variable PORT, then configuration and last 3000
app.set('port', process.env.PORT || config.get('port') || 3000); app.set('port', process.env.PORT || config.port || 3000);
// Set default ip: first environment variable IOP, then configuration and last '127.0.0.1' // Set default ip: first environment variable IOP, then configuration and last '127.0.0.1'
app.set('ip', process.env.IP || config.get('ip') || '127.0.0.1'); app.set('ip', process.env.IP || config.ip || '127.0.0.1');
const server = app.listen(app.get('port'), () => { const server = app.listen(app.get('port'), () => {
log.info(`Express server listening on port ${server.address().port}`); log.info(`Express server listening on port ${server.address().port}`);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment