为express.js更新Cookie会话

问题描述 投票:3回答:1

我正在使用cookie-session模块供Expresss.js处理会话。

我希望每次页面加载(或ajax调用)时都更新会话。这就是他们通常在任何地方工作的方式。

文档未对此说什么。

我尝试这样做,但没有成功:

app.use(function(req,res,next ){
     req.sessionOptions.maxAge = 20*1000;
     return next();
});
node.js express express-session
1个回答
3
投票
var cookieSession = require('cookie-session') app.use(cookieSession({ key: cookieKey, secret: cookieSecret, maxAge: 1 * 60 * 60 * 1000 // 1 hour (rolling) }) ); app.get('*', function(req, res, next) { // To update the session expiration time we need to send the new // expiration in the response cookie. // To send again the response cookie to the client we need to // update the session object. req.session.fake = Date.now(); next(); });

确实,如果会话对象does not change,cookie-session v。1.2.0没有set the Set-Cookie header将响应cookie发送到客户端。

© www.soinside.com 2019 - 2024. All rights reserved.