UNPKG

@webgap/configuration

Version:

WebGAP configurations module. Contains the base Configurations Schema for all webgap components.

65 lines (59 loc) 2.01 kB
/** * (C) Copyright 2014 WebGAP (http://www.webgap.eu/). * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * * Created by: ManuelMartins * Created on: 04-05-2014 * */ "use strict"; var convict = require('convict'); // load configurations schema var configurationSchemaFile = loadConfigurationsSchema(); // load configurations file var configurationJSONFile = loadConfigurationsFile(); // load and validate configurations var configurations = convict(configurationSchemaFile).load(configurationJSONFile).validate(); /** * Loads the configurations schema. * The schema can be overridden using the 'NODE_APP_SCHEMA' environment variable. * * @returns {*} */ function loadConfigurationsSchema() { var schema = process.env.NODE_APP_CONF_SCHEMA || './configurations-schema.json'; return require(schema); } /** * Tries to load the configurations file, if it does not exist returns an empty object and thus default * configuration from the configuration schema applies. * * @returns {*} */ function loadConfigurationsFile() { try { return require(process.env.NODE_APP_CONF); } catch (err) { console.warn('Cannot load configurations file. An empty object will be used instead.'); console.warn(err); return {}; } } /** * Configurations are loaded from a file defined as an environment variable 'NODE_APP_CONF' * * e.g.: /home/webap/portal/conf/development.json */ module.exports = configurations;