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/*
config.json
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', () => {
.pipe(gulp.dest('build')); // move compiled files to build directory
// copy configuration file to build directory
gulp.src('config/config.json')
.pipe(gulp.dest('build/config'));
gulp.src('config/test_config.json')
.pipe(gulp.dest('build/config'));
gulp.src('config.json')
.pipe(gulp.dest('build'));
});
gulp.task('build', ['compile']);
......
......@@ -12,7 +12,7 @@ const log = require(`${libs}/log`)(module);
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
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 nconf = require('nconf');
let conf = require(`${process.cwd()}/config.json`);
const CONFIG_DIR = `config`
let config_file;
conf = conf[process.env.NODE_ENV];
switch(process.env.NODE_ENV) {
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;
module.exports = conf;
......@@ -6,16 +6,16 @@ const config = require(`${libs}/config`);
// Connection options
const poolOptions = {
nrConnections: config.get('monetdb:nrConnections'),
nrConnections: config.monetdb.nrConnections,
};
// Configuration options
const options = {
host: config.get('monetdb:host'),
port: config.get('monetdb:port'),
dbname: config.get('monetdb:dbname'),
user: config.get('monetdb:user'),
password: config.get('monetdb:password'),
host: config.monetdb.host,
port: config.monetdb.port,
dbname: config.monetdb.dbname,
user: config.monetdb.user,
password: config.monetdb.password,
};
// Connection singleton
......
......@@ -8,7 +8,7 @@ const mongoose = require('mongoose');
module.exports = () => {
// 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}`);
// Connection singleton
const db = mongoose.connect(mongoUri);
......
......@@ -47,7 +47,7 @@ function logger(module) {
],
exitOnError: false,
});
if (!config.get('debug')) {
if (!config.debug) {
log.remove('debug-log');
}
return log;
......
const mongoose = require('mongoose')
const libs = `${process.cwd()}/libs`;
const config = require(`${libs}/config`);
const log = require(`${libs}/log`)(module);
const Schema = mongoose.Schema;
......
......@@ -6,7 +6,6 @@ const libs = `${process.cwd()}/libs`;
const log = require(`${libs}/log`)(module);
const config = require(`${libs}/config`);
const squel = require('squel');
......
......@@ -9,10 +9,10 @@ const log = require(`${libs}/log`)(module);
const app = require(`${libs}/app`);
// 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'
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'), () => {
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