// Generated by CoffeeScript 1.6.3 /* Configuration ============= > Loads the configuration file and acts as an interface to it. */ (function() { var exports, fetchProp, fs, loadConfigFile, log, path, _this = this; log = require('./logging'); fs = require('fs'); path = require('path'); /* ##Module call 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') { loadConfigFile(args.relPath); } return module.exports; }; /* Tries to load a configuration file from the path relative to this module's parent folder. Reads the config file synchronously from the file system and try to parse it. @private loadConfigFile @param {String} relPath */ loadConfigFile = function(relPath) { var e; try { _this.config = JSON.parse(fs.readFileSync(path.resolve(__dirname, '..', relPath))); if (_this.config && _this.config.http_port && _this.config.db_port && _this.config.crypto_key && _this.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')); /* Fetch a property from the configuration @private fetchProp( *prop* ) @param {String} prop */ fetchProp = function(prop) { var _ref; return (_ref = _this.config) != null ? _ref[prop] : void 0; }; /* ***Returns*** true if the config file is ready, else false @public isReady() */ exports.isReady = function() { return _this.config != null; }; /* ***Returns*** the HTTP port @public getHttpPort() */ exports.getHttpPort = function() { return fetchProp('http_port'); }; /* ***Returns*** the DB port* @public getDBPort() */ exports.getDBPort = function() { return fetchProp('db_port'); }; /* ***Returns*** the crypto key @public getCryptoKey() */ exports.getCryptoKey = function() { return fetchProp('crypto_key'); }; /* ***Returns*** the session secret @public getSessionSecret() */ exports.getSessionSecret = function() { return fetchProp('session_secret'); }; }).call(this);