簡體   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