Express 2.x -> 3.x 보기 도우미 등록 방법

1415 단어
2.x:
<!-- lang: js -->
app.helpers({
<!-- lang: js -->
  config: config,
<!-- lang: js -->
  title: config.title
<!-- lang: js -->
});
<!-- lang: js -->
app.dynamicHelpers({
<!-- lang: js -->
  // csrf 
<!-- lang: js -->
  csrf: function(req,res) {
<!-- lang: js -->
    return req.session ? req.session._csrf : '';
<!-- lang: js -->
  },
<!-- lang: js -->
  req: function(req,res) {
<!-- lang: js -->
    return req;
<!-- lang: js -->
  },
<!-- lang: js -->
  userInfo: function(req,res){
<!-- lang: js -->
    return req.session.user;
<!-- lang: js -->
  }
<!-- lang: js -->
});

3.x
<!-- lang: js -->
//app.helpers() 
<!-- lang: js -->
app.locals({
<!-- lang: js -->
  config: config,
<!-- lang: js -->
  title: config.title
<!-- lang: js -->
});
<!-- lang: js -->
//app.dynamicHelpers
<!-- lang: js -->
app.use(function(req, res, next){
<!-- lang: js -->
  res.locals.title = config['title']
<!-- lang: js -->
  res.locals.csrf = req.session ? req.session._csrf : '';
<!-- lang: js -->
  res.locals.req = req;
<!-- lang: js -->
  res.locals.session = req.session;
<!-- lang: js -->
  next();
<!-- lang: js -->
});
<!-- lang: js -->
app.use(app.router);

좋은 웹페이지 즐겨찾기