config.js tests
This commit is contained in:
+13
-2
@@ -1,16 +1,27 @@
|
||||
const refConfig = require('./default_config.json');
|
||||
const srcConfig = require('../config.json');
|
||||
const fs = require('fs');
|
||||
|
||||
const merge = function (ref, src) {
|
||||
if (typeof ref !== typeof src) {
|
||||
console.log(ref, src, ref);
|
||||
return ref;
|
||||
} else if (typeof ref === 'object') {
|
||||
const out = {};
|
||||
Object.keys(ref).forEach(key => out[key] = merge(ref[key], src[key]));
|
||||
return out;
|
||||
} else {
|
||||
console.log(ref, src, src);
|
||||
return src;
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = merge(refConfig, srcConfig);
|
||||
module.exports = function () {
|
||||
try {
|
||||
let configData = fs.readFileSync('./config.json');
|
||||
let config = JSON.parse(configData);
|
||||
return merge(refConfig, config);
|
||||
} catch (error) {
|
||||
console.error('Failed to load config.json');
|
||||
return refConfig;
|
||||
}
|
||||
};
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"nodePort": 3000,
|
||||
"dataDir": "data",
|
||||
"node_port": 3000,
|
||||
"data_dir": "data",
|
||||
"modules" : {
|
||||
"plantuml" : false,
|
||||
"rss": true,
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
const config = require('./config');
|
||||
const config = require('./config')();
|
||||
const app = require('./app')(config);
|
||||
|
||||
app.listen(config.nodePort, () => {
|
||||
console.log(`gitblog.md server listening on port ${config.nodePort}`);
|
||||
app.listen(config['node_port'], () => {
|
||||
console.log(`gitblog.md server listening on port ${config['node_port']}`);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user