续订express.js的Cookie会话

我正在使用用于Expresss.js的cookie会话模块来处理会话。

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

文件没有说一个字。

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

app.use(function(req,res,next ){ req.sessionOptions.maxAge = 20*1000; return next(); }); 

我怀疑你没有将响应cookie发送给客户端。 我用一个中间件解决了同样的问题(使用快速和cookie会话),该中间件为每个get发送一个包含不同值的cookie:

 app.use(session({ 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(); }); 

事实上,如果会话对象不改变 ,cookie-session v.1.2.0不会设置Set-Cookie头将响应cookie发送给客户端。