将API从codesandbox.io前端沙箱发布到后端devbox时被CORS策略错误阻止

问题描述 投票:0回答:1

我正在开发一个项目,前端和后端都是在codesandbox.io上使用React和Node设计的。我的前端将数据发布到具有 cors 策略来源的后端,设置为接受来自前端的请求。

前端代码:

submitData(server_url, { action: rate.action });

上面的代码在幕后使用了axios。我已确保适用于其他端点(即不是来自codesandbox的端点)

后端代码:

app.use( cors({ origin: client_url, }), );

我添加了 cors 以仅接受来自 client_url 的请求。 在这种情况下,当调用

submitData
时,我收到以下错误。

Access to XMLHttpRequest at ******************** from origin ***************** has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.

cors codesandbox
1个回答
0
投票

我必须在 axios post 请求中使用这个位置吗?

© www.soinside.com 2019 - 2024. All rights reserved.