settings.js 860 Bytes


// # boot - settings

var _ = require('underscore')
var util = require('util')
var mergeDefaults = require('../utils/merge-defaults')
var IoC = require('electrolyte');
exports = module.exports = function (config) {

    var settings = {}

    var env = process.env.NODE_ENV || 'development'

    if (!_.isObject(config[env]))
        throw new Error(util.format('Unknown environment %s', env))

    if (env === 'development') {
        try {
            return IoC.create('local').then(function (data) {
                var local = data;
                if (_.isObject(local)) {
                    return mergeDefaults(settings, local)
                }
            });

        } catch (e) {
        }
    }

    mergeDefaults(settings, config[env], config.defaults)

    return settings

};

exports['@singleton'] = true;
exports['@require'] = ['config'];