01-settings.js 1.0 KB

// # settings

var compress = require('compression');
var IoC = require('electrolyte');
var https = require('https');
var http = require('http');

exports = module.exports = function (settings) {
    var app = this;
    // 设置环境变量
    app.set('env', settings.server.env);

    //设置默认的试图目录
    app.set('views', settings.server.dir);

    //设置默认的试图引擎
    app.set('view engine', settings.server.engine);

    if (settings.server.env === 'development') {
        //开发模式下视图美化输出
        app.locals.pretty = true;
    }
    if (settings.server.env === 'production') {
        //启动视图缓存
        app.enable('view cache');
        //默认gzip压缩返回数据
        // this overwrites res.write and res.end functions
        app.use(compress());
    }
    if (settings.server.ssl.enabled) {
        this.server = https.createServer(settings.server.ssl.options, this);
    } else {
        this.server = http.createServer(this);
    }

};

exports['@require'] = ['igloo/settings'];