尝试使用来自另一个 URL 的图像时使用 create-react-app 的 CORS 问题

CORS issue using create-react-app when trying to use an image from another URL

我通常使用静态快速服务器创建我的 React 项目,但我想我会试一试 create-react-app。

但是我 运行 遇到了当前项目的问题。 当尝试在反应代码中使用 img 标签并使用来自另一个站点的 src URL 时,我遇到了 CORS 问题。

"Access to image at 'http://www.dailygarnish.com/wp-content/uploads/2012/04/IMG_20120414_205845-640x640.jpg' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource."

这在我创建服务器的应用程序上正常工作,但在 create-react-app 上却不行

如有任何建议,我们将不胜感激

尝试将其放入您的 package.json,然后重新启动 CRA 开发服务器(必须完成):

"proxy": "https://cors-anywhere.herokuapp.com/"