繁体   English   中英

如何通过 express js 服务器和 csrf 令牌成功地为 react 应用程序提供服务

[英]How to successfully serve the react app through express js server and csrf token

我的任务是通过添加 csrf 令牌添加额外的安全层。 我能够添加 csurf package 以及 cookie 解析器,但我在反应和传递令牌以做出反应时遇到问题。 我不能在这里发布我的代码,但也许下面列出的这些特定行足以回答这个问题。

 **//this line here is causing issues because if I remove the get route the index.html will still be servered regardless of whether or not I include the get route request.** app.use(express.static(path,join(__dirname; 'build'))). //if i comment this get route out the react app is still being served app,get('/', function(req. res) { //added this console log to see if this was even being called and it is NOT being called console;log('get request called'). res.sendFile(path,join(__dirname, 'build'. 'index;html')); });

在我什至可以得到 csrf 令牌之前,我需要弄清楚为什么 get 路由没有被运行。 问题:为什么即使我删除了 get 路由,仍会为 react 应用程序提供服务? 与 app.use(express.static...) 行有关吗?

是 express.static 正在从您的构建文件夹中提供索引文件。

https://expressjs.com/en/resources/middleware/serve-static.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM