【问题标题】:Refused to load the image because it violates the following Content Security Policy directive: "default-src 'none'". Angular 8拒绝加载图像,因为它违反了以下内容安全策略指令:“default-src 'none'”。角 8
【发布时间】:2020-03-22 02:05:35
【问题描述】:

在 heroku 上上传 angular 8 应用程序后,我在构建中没有错误,但在控制台错误文本中。

Refused to load the image 'https://MYAPPLICATION.herokuapp.com/favicon.ico' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'img-src' was not explicitly set, so 'default-src' is used as a fallback.

MYAPPLICATION.herokuapp.com/:1 Failed to load resource: the server responded with a status of 404 (Not Found)

我花了很多时间试图解决这个问题,但没有成功。帮助?我阅读了其他人的解决方案,但没有任何帮助。如何

编辑编辑编辑:

所有消息错误

拒绝加载图像“https://MYAPP.herokuapp.com/favicon.ico”,因为它违反了以下内容安全策略指令:“default-src 'none'”。请注意,'img-src' 没有显式设置,因此 'default-src' 用作备用。

加载资源失败:服务器响应状态为 404(未找到)

已解决> 好的,我解决了这个问题。 我有来自后端的 Api Cors 问题,但我使用的是在 localhost 中工作的块 cors 扩展,但是项目何时转到服务器不起作用。我没有真正的错误消息。

【问题讨论】:

  • 这与内容安全策略有关
  • @c_ogoo 好的怎么解决?

标签: angular heroku server


【解决方案1】:

您是否检查过在 index.html 中添加以下元标记?

<meta http-equiv="Content-Security-Policy" content="default-src 'none'; connect-src 'self';font-src 'self'; img-src 'self' data: https:; style-src 'self' ; script-src 'self'">

希望这会有所帮助:)

【讨论】:

  • 为了提高答案的质量,可能值得在 CSP 上添加指向 MDN 文档的链接,并且可能是对您的解决方案含义的基本解释
  • 当我打开 heroku 网站时,我只看到空白页面,其中包含 Not Found 文本和控制台错误?如何更好地解释?
  • @pichlou 这对我没用 :( 我在任何论坛上都发现了,但对我没用。也许可以解决回到旧版本
  • @pichlou 添加此元标记后,我的 localost 没有工作。看看我的错误 injectStylesIntoStyleTag.js:130 拒绝应用内联样式,因为它违反了以下内容安全策略指令:“style-src 'self'”。启用内联执行需要“unsafe-inline”关键字、哈希(“sha256-47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=”)或随机数(“nonce-...”)。还有一个 Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not a allowed source of script in the following Content Security Policy directive: "script-src 'self'"。
  • 这行不通。这将与应用程序的其他部分发生冲突。例如,如果您这样做,样式表现在将不会加载
猜你喜欢
  • 2021-04-15
  • 1970-01-01
  • 1970-01-01
  • 2022-07-27
  • 1970-01-01
  • 2021-05-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多