📜  从 ejs 视图访问会话数据 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:23.298000             🧑  作者: Mango

代码示例1
app.use(function(req, res, next) {
  res.locals.user = req.session.user;
  next();
});

/*


You can use res.locals to expose particular data to all templates.

In your situation, you could add the following middleware to Express:


This will make a user variable available in all your templates.

You do need to make sure that you add that middleware after req.session has been set (which is usually after express-session has been added to the middleware chain).
*/