javascript 错误:配置错误的 csrf - Express JS 4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23997572/
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
Error: misconfigured csrf - Express JS 4
提问by Jér?me Verstrynge
I am trying to enable the csrfmodule of Express 4 in an existing application.
我正在尝试在现有应用程序中启用Express 4的csrf模块。
I have added the following code:
我添加了以下代码:
var csrf = require('csurf')
...
app.use(csrf());
I have started my application and I get:
我已经开始我的申请,我得到:
Error: misconfigured csrf
and a stack trace. Nothing else.
和堆栈跟踪。没有其他的。
I have checked the documentation, but it is unclear. Can someone help? What is the minimum configuration required to use this module?
我检查了文档,但不清楚。有人可以帮忙吗?使用此模块所需的最低配置是什么?
回答by Jér?me Verstrynge
I have found the solution. The call to app.use(csrf())
must be set after app.use(cookieParser())
AND app.use(session({...})
.
我找到了解决办法。调用app.use(csrf())
必须在app.use(cookieParser())
AND之后设置app.use(session({...})
。
回答by Mike
If you're using Redis as a session store and the server isn't running, you will also get a misconfigured error.
如果您使用 Redis 作为会话存储并且服务器没有运行,您也会收到配置错误的错误。