express视图助手dynamicHelpers和helpers从2.x到3.x的变化

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);