我正在使用cookie-session模块供Expresss.js处理会话。
我希望每次页面加载(或ajax调用)时都更新会话。这就是他们通常在任何地方工作的方式。
文档未对此说什么。
我尝试这样做,但没有成功:
app.use(function(req,res,next ){
req.sessionOptions.maxAge = 20*1000;
return next();
});
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发送到客户端。