forked from TheCacophonyProject/cacophony-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
executable file
·38 lines (29 loc) · 905 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
const fs = require('fs');
const path = require('path');
// Set some default configuration
var server = {
loggerLevel: "info",
};
function loadConfig(configPath) {
configPath = path.resolve(configPath);
checkConfigFileExists(configPath);
const config = require(configPath);
for (var key in config) {
exports[key] = config[key];
}
checkDatabaseConfigAvailable(config);
return exports;
}
function checkConfigFileExists(configPath) {
if (!fs.existsSync(configPath)) {
throw "Config file " + configPath + " does not exist. See README.md for config setup. " +
"NB: The default config file has been renamed to ./config/app.js";
}
}
function checkDatabaseConfigAvailable(config) {
if (!('database' in config)) {
throw "Could not find database configuration. database.js has been merged into app.js";
}
}
exports.loadConfig = loadConfig;
exports.server = server;