【发布时间】:2017-09-15 19:07:47
【问题描述】:
是否可以在 app.js 中有条件地使用app.use?
Express cookie-session 可以 not change the value of maxAge dynamically 并且我正在考虑做这种事情,但我遇到了一些错误:
app.use(function(req,res,next ){
if(typeof req.session == 'undefined' || req.session.staySignedIn === 'undefined'){
//removing cookie at the end of the session
cookieSession({
httpOnly: true,
secure: false,
secureProxy: true,
keys: ['key1', 'key2']
});
}else{
//removing cookie after 30 days
cookieSession({
maxAge: 30*24*60*60*1000, //30 days
httpOnly: true,
secure: false,
secureProxy: true,
keys: ['key1', 'key2']
});
}
next();
});
而不是正常使用它:
app.use(cookieSession({
httpOnly: true,
secure: false,
secureProxy: true,
keys: ['key1', 'key2']
}));
现在我收到以下错误:
无法读取未定义的属性“用户”
我相信它指的是这条线(虽然它没有说明确切的位置)
req.session.user;
【问题讨论】:
标签: javascript node.js express cookie-session