我无法将我的React前端和后端Nodejs链接起来

我正在尝试在我的node js react应用中对自己进行身份验证。 这是我的代码,也是我的错误。

Authentication Code

Authentication Error

duoduogo 回答:我无法将我的React前端和后端Nodejs链接起来

您应该允许CORS访问,为此,您应该使用cors库,然后在app.js文件中这样使用它:

const cors = require("cors");

    app.use(cors({
        origin: ["http://localhost:3000"],methods: ["GET","POST","PUT","DELETE"],credentials: true // enable set cookie
    }));

但是,请更新您的问题并张贴所有代码和错误。

,

您定义了CORS政策,并定义了类似的库

const cors=require('cors');

链接:https://expressjs.com/en/resources/middleware/cors.html

本文链接:https://www.f2er.com/3109646.html

大家都在问