openhim-core
Version:
The OpenHIM core application that provides logging and routing of http requests
73 lines (46 loc) • 1.86 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.config = exports.appRoot = void 0;
var _nconf = _interopRequireDefault(require("nconf"));
var _path = _interopRequireDefault(require("path"));
var _fs = _interopRequireDefault(require("fs"));
var _winston = _interopRequireDefault(require("winston"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const appRoot = _path.default.resolve(__dirname, '../..');
/*
* Define the default constructor
*/
exports.appRoot = appRoot;
function Config() {
// Get the argument-value to use
_nconf.default.argv().env('_'); // don't read NODE:ENV from nconf as it could be overwritten by any env var starting with 'NODE_'
const environment = process.env.NODE_ENV;
const conf = _nconf.default.get('conf'); // Load the configuration-values
// user specified config override
if (conf) {
if (!_fs.default.existsSync(conf)) {
_winston.default.warn(`Invalid config path ${conf}`);
}
_nconf.default.file('customConfigOverride', conf);
} // environment override
if (environment) {
const envPath = `${appRoot}/config/${environment}.json`;
if (!_fs.default.existsSync(envPath)) {
_winston.default.warn(`No config found for env ${environment} at path ${envPath}`);
}
_nconf.default.file('environmentOverride', `${appRoot}/config/${environment}.json`);
} // load the default config file
_nconf.default.file('default', `${appRoot}/config/default.json`); // Return the result
}
/*
* This function return the value that was set in the key-value store
*/
Config.prototype.get = key => _nconf.default.get(key);
/*
* This function constructs a new instanse of this class
*/
const config = new Config();
exports.config = config;
//# sourceMappingURL=config.js.map