webapi-eca/js-coffee/config.js
Dominic Bosch 8c115aa71d What a wonderful detour over docco, only to recognize that it was always possible to auto generate documentation.
... if one would just define the correct folder...
at least deep knowledge about docco now, plus that it doesn't use glob (leaves it a user task...) while groc does use glob to resolve file paths, yay!
2013-11-20 15:41:41 +01:00

111 lines
2.3 KiB
JavaScript

// Generated by CoffeeScript 1.6.3
(function() {
'use strict';
var config, exports, fetchProp, fs, loadConfigFile, log, path;
path = require('path');
log = require('./logging');
fs = require('fs');
config = null;
/*
Calling the module as a function will make it look for the `relPath` property in the
args object and then try to load a config file from that relative path.
@param {Object} args
*/
exports = module.exports = function(args) {
args = args != null ? args : {};
log(args);
if (typeof args.relPath === 'string') {
loadConfigFiles(args.relPath);
}
return module.exports;
};
/*
@Function loadConfigFile
Tries to load a configuration file from the path relative to this module's parent folder.
@param {String} relPath
*/
loadConfigFile = function(relPath) {
var e;
try {
/* We read the config file synchronously from the file system and try to parse it*/
config = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', relPath)));
if (config && config.http_port && config.db_port && config.crypto_key && config.session_secret) {
return log.print('CF', 'config file loaded successfully');
} else {
return log.error('CF', new Error("Missing property in config file, requires:\n- http_port\n- db_port\n- crypto_key\n- session_secret"));
}
} catch (_error) {
e = _error;
e.addInfo = 'no config ready';
return log.error('CF', e);
}
};
loadConfigFile(path.join('config', 'config.json'));
/* Answer true if the config file is ready, else false*/
exports.isReady = function() {
return config != null;
};
/*
Fetch a property from the configuration
@param {String} prop
*/
fetchProp = function(prop) {
return config != null ? config[prop] : void 0;
};
/*
Get the HTTP port
*/
exports.getHttpPort = function() {
return fetchProp('http_port');
};
/*
Get the DB port
*/
exports.getDBPort = function() {
return fetchProp('db_port');
};
/*
Get the crypto key
*/
exports.getCryptoKey = function() {
return fetchProp('crypto_key');
};
/*
Get the session secret
*/
exports.getSessionSecret = function() {
return fetchProp('session_secret');
};
}).call(this);