node.js express 4.0 ,带有奇怪警告消息的 express-session
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24477035/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
express 4.0 , express-session with odd warning message
提问by jmls
I am trying to work through setting up a nodejs app using express 4.x. After stumbling through the middleware-removal issues, I finally got it working.
我正在尝试使用 express 4.x 设置 nodejs 应用程序。在解决了中间件删除问题后,我终于让它工作了。
however, there was a couple of warning messages in the following line of code :
但是,在以下代码行中有几条警告消息:
app.use(session({secret: '<mysecret>'})
these warnings were :
这些警告是:
Sun, 29 Jun 2014 12:45:10 GMT express-session deprecated pass resave option; default value will change at lib\config\express.js:55:11
Sun, 29 Jun 2014 12:45:10 GMT express-session deprecated pass saveUninitialized option; default value will change at lib\config\express.js:55:11
in the documentation, the default values for resave and saveUninitialized are true.
在文档中, resave 和 saveUninitialized 的默认值为 true。
so, changing the code to read
因此,更改代码以读取
app.use(session({secret: '<mysecret>',
saveUninitialized: true,
resave: true}));
got rid of the warnings.
摆脱了警告。
So, to get to the point of the question:
所以,进入问题的重点:
why should I have to pass these values in if they are the default values, and why don't I have to pass in the other options ?
如果它们是默认值,为什么我必须传入这些值,为什么我不必传入其他选项?
采纳答案by mscdex
As the warnings say, the default values will change so they want to ensure that by setting the values explicitly now, you won't run into unexpected behavior when the defaults do change (in the near future).
正如警告所说,默认值会发生变化,因此他们希望通过现在明确设置值来确保,当默认值确实发生变化时(在不久的将来),您不会遇到意外行为。
回答by Ben
I found issue useful:
我发现问题很有用:
https://github.com/expressjs/session/issues/56
https://github.com/expressjs/session/issues/56
app.use(session({
secret: cookie_secret,
resave: true,
saveUninitialized: true
}));
回答by DragonKnight
I don't have enough rep to add this as comment. I added this for my default value of Ben's answer.
我没有足够的代表将其添加为评论。我添加了这个作为 Ben 答案的默认值。
secret: process.env.SESSION_SECRET || '<mysecret>',
回答by Vijay Prajapati
app.use(session({
cookieName: 'session',
secret: 'eg[isfd-8yF9-7w2315df{}+Ijsli;;to8',
duration: 30 * 60 * 1000,
activeDuration: 5 * 60 * 1000,
httpOnly: true,
secure: true,
ephemeral: true,
resave: true,
saveUninitialized: true
}));

