app.js 1.8 KB
/**
 * yo app 入口
 * @author h1bomb
 */

var yo = require('yo.js'); //引用YO框架
var staticDir = require('./staticConfig').staticDir; //获取静态文件的不同环境配置
var auth = require('./mid/auth');//认证中间件
var pageModule = require('./mid/pageModule');//页面加载js中间件
var grayroute = require('./mid/grayroute');//灰度界面中间件
var config = require('./config/common');




var qiniu = require('qiniu');
qiniu.conf.ACCESS_KEY = 'BwWhoJN536BnV3CzlE20AjNKC9O2bP0l5tFpKsDU';
qiniu.conf.SECRET_KEY = '_x2VtO7fEmylgjojmLi7qwTBtRm30S8BrO0FxOPK';
var uptoken = new qiniu.rs.PutPolicy('cmsimg01');


var app = yo( {
    //初始化yo的app
    appPath: __dirname + '/../', //应用所在目录
    tempExt: 'html', //模板引擎的扩展名
    envStatic: staticDir, //静态文件的环境配置
    session: {
        secret: 'yohobuy.portal', //session配置

        cookie: { secure: false , maxAge: 3600000 }//session cookie失效时间1小时
    },               
    seStore:config.redis,
    port:30012,
    beforeMid:function(app,mids) {//使用handlebars-layouts
        require('handlebars-layouts').register(mids.hbs.handlebars);
    },
    beforeCustMid: function (app, routers) {
        app.use(auth);//权限验证
        app.use(grayroute(routers));//灰度界面中间件
        app.use(pageModule);//客户端js模块加载
    },
    afterRender: function (res, str) {//在渲染完html后,加入模块调用的js
        if (res.locals.layout === false && res.locals.module) {
            str += '<script type="text/javascript">seajs.use("' + res.locals.module + '",function(m){m.init();});</script>';
        }
        str += "<input type='hidden' id='uptoken' value='" + uptoken.token() + "'>"
        return str;
    }
});



require('./stub/routers')(app); //添加桩服务