【问题标题】:create-react-app issue: Refused to load the image '<URL>' because it violates the following Content Security Policy directive:create-react-app 问题:拒绝加载图像“<URL>”,因为它违反了以下内容安全策略指令:
【发布时间】:2020-12-13 17:32:46
【问题描述】:

我正在尝试将 react 应用程序部署到 Heroku。我有一个 NodeJs/Express API,它正在为我使用 create-react-app 创建的应用提供服务。

我正在尝试在我的站点上的外部 API (https://www.thecocktaildb.com) 的标签中显示图像,但在生产中我继续收到以下错误:

Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self' data:".

我尝试在我的 public/index.html 文件中使用以下代码 sn-p 的许多变体来解决这个问题,但到目前为止没有任何效果。

<meta
    http-equiv="Content-Security-Policy"
    content="img-src 'self' https://www.thecocktaildb.com data:;"
/>

我已经用完了可以尝试的东西,并且无法在任何地方找到解决方案。请帮忙。

【问题讨论】:

    标签: node.js reactjs express heroku create-react-app


    【解决方案1】:

    https://stackoverflow.com/a/40360666/11624647

    尝试添加标签

    img-src * 'self' data: https:
    

    代码:

    <meta http-equiv="Content-Security-Policy" content="default-src *;
       img-src * 'self' data: https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' *;
       style-src  'self' 'unsafe-inline' *">
    

    【讨论】:

    • 遗憾的是这不起作用。我收到了Refused to load the image '&lt;URL&gt;' because it violates the following Content Security Policy directive: "img-src 'self' data:". create-react-app 可以在其他地方进行配置吗?
    • 确保在 thecocktaildb.com 中启用了特定网站允许访问第三方的 cors
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-29
    • 2021-04-15
    • 1970-01-01
    • 2015-09-21
    • 2012-11-27
    • 2020-06-23
    相关资源
    最近更新 更多