This repository has been archived on 2026-05-02. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
GitBlog.md/src/config.js
T
Clément GOUIN f9a2db38d2 code convention
2019-06-20 10:49:51 +02:00

25 lines
691 B
JavaScript

const refConfig = require('./config.default.json');
const fs = require('fs');
const merge = (ref, src) => {
if (typeof ref !== typeof src) {
return ref;
} else if (typeof ref === 'object') {
const out = {};
Object.keys(ref).forEach((key) =>out[key] = merge(ref[key], src[key]));
return out;
} else {
return src;
}
};
module.exports = () => {
try {
let configData = fs.readFileSync('config.json', {encoding:'UTF-8'});
let config = JSON.parse(configData);
return merge(refConfig, config);
} catch (error) {
console.error('Failed to load config.json : '+error);
return refConfig;
}
};