2016年(89)
分类: Web开发
2016-03-10 22:18:53
2.x:
app.helpers({ config: config, title: config.title }); app.dynamicHelpers({ //防止csrf攻击 csrf: function(req,res) { return req.session ? req.session._csrf : ''; }, req: function(req,res) { return req; }, userInfo: function(req,res){ return req.session.user; } });
3.x
//app.helpers() app.locals({ config: config, title: config.title }); //app.dynamicHelpers app.use(function(req, res, next){ res.locals.title = config['title'] res.locals.csrf = req.session ? req.session._csrf : ''; res.locals.req = req; res.locals.session = req.session; next(); }); app.use(app.router);