我在前端使用ReactJS,在后端使用Django API。我目前正在通过将本地主机(后端)连接到 ngrok URL 并使用已经在 PROD 中自己的测试环境中的 ReactJS 前端点击该 ngrok URL 来测试一些功能。
POST 请求工作得很好,但是当有 GET 请求时,在 chrome 的开发者工具中,我得到以下信息:
Access to fetch at 'https://'{NGROK URL} from origin 'https://{PROD URL}.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
我已经包含了必要的 CORS_ALLOWED_ORIGINS 甚至 CORS_ALLOW_ALL_ORIGINS。
当我从前端(localhost)到后端(localhost)测试它时,它工作正常。
有谁知道为什么这不起作用?
来自ngrok的PM在这里。这听起来像是我们一直看到的一个问题,当我们通过浏览器提供流量时,为免费帐户添加的网络钓鱼插页式页面会因某种原因被触发。
我们刚刚合并了一项更改,该更改应该可以阻止 CORS 错误,并至少向您显示阻止您的实际页面。要绕过插页式广告,请按照 这些说明 并将
ngrok-skip-browser-warning
添加到对 ngrok url 的请求中。