在大多数 ExpressJs 示例中,我发现使用 cookie-parser
和 express-session
。
如果我可以在没有它的情况下使用 req.session.name
访问 session 数据,在什么情况下(或好处)我应该使用 cookie-parser
?
最佳答案
对于 future 不起眼的编码人员,他们会偶然发现这一点 - 我发布了一个最新的答案:
正如 express-session
中间件的官方描述在这里所说:express-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. Usingcookie-parser
may result in issues if the secret is not the same between this module andcookie-parser
.
因此,只需使用 express-session 中间件,祝您有美好的一天。
关于node.js - 什么时候应该将 cookie-parser 与 express-session 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27961320/