问题描述
在大多数ExpressJs示例中,我发现使用 cookie-parser
和 express-session
。
'从版本1.5.0开始,不再需要使用cookie解析器中间件来使这个模块工作。此模块现在直接读取和写入req / res上的cookie。如果该模块和cookie解析器之间的秘密不一样,使用cookie解析器可能会导致问题。
因此,只需使用Express会话中间件, 。
In most ExpressJs example, I found using cookie-parser
with express-session
.
If I could access session data with req.session.name
without it, in what case ( or benefits ) should I be using cookie-parser
?
For future humble coders, that will stumble upon this - I'm posting up-to-date answer:
As official description of express session middleware says here: https://github.com/expressjs/session
'Since version 1.5.0, the cookie-parser middleware no longer needs to be used for this module to work. This module now directly reads and writes cookies on req/res. Using cookie-parser may result in issues if the secret is not the same between this module and cookie-parser.'
Therefore just use Express session middleware and have a nice day.
这篇关于什么时候应该使用cookie解析器与express-session?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!