简体   繁体   English

获取“违反以下内容安全策略指令:”default-src 'none'”。将 Angular 应用程序部署到 heroku 时出错

[英]Getting a "violates the following Content Security Policy directive: "default-src 'none'". error when deploying an angular app to heroku

I'm trying to deploy my angular app to Heroku and I've been having a lot of problems.我正在尝试将我的 angular 应用程序部署到 Heroku,但遇到了很多问题。 I'm getting an error "Refused to load the image ' https://thawing-fortress-79986.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."我收到错误消息“拒绝加载图像‘ https://thawing-fortress-79986.herokuapp.com/favicon.ico ’,因为它违反了以下内容安全策略指令:‘default-src‘none’”。请注意,'img-src' 未明确设置,因此使用 'default-src' 作为后备。”

I've tried adding http://* https://* 'unsafe-inline';我试过添加 http://* https://* 'unsafe-inline'; script-src 'self' http://* https://* 'unsafe-inline' 'unsafe-eval'"> to my index.html and I've tried running ng build but that didn't fix anything script-src 'self' http://* https://* 'unsafe-inline' 'unsafe-eval'"> 到我的 index.html 并且我试过运行 ng build 但这并没有解决任何问题

Not sure where in my code that this error is coming from but here is part of my server不确定我的代码中这个错误来自哪里,但这是我服务器的一部分

app.use(express.static(__dirname + '/dist'));

app.get('/*', function(req, res) {
    res.sendFile(path.join(__dirname + '/dist/index.html'));
});

Here is part of my package.json这是我的 package.json 的一部分

  "name": "*******",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "node server.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

I tried to deploy to angular, I want it to start my server and load my static angular files, but it gives me an "internal server error" on the page and a ""Refused to load the image 'https://thawing-fortress-79986.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."" in the console logout.我试图部署到 angular,我希望它启动我的服务器并加载我的静态 angular 文件,但它在页面上给了我一个“内部服务器错误”和一个""Refused to load the image 'https://thawing-fortress-79986.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."" in the console logout. ""Refused to load the image 'https://thawing-fortress-79986.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."" in the console logout.

Any help would be greatly appreciated任何帮助将不胜感激

probably the path is not given correctly.可能路径没有正确给出。 goto dist folder and check the right path to index.html转到 dist 文件夹并检查 index.html 的正确路径

example :例子 :

'/dist/**<your app name>**' && '/dist/**<your app name>**/index.html'

and change the path in following two lines并在以下两行中更改路径

app.use(express.static(__dirname + '/dist'));
res.sendFile(path.join(__dirname + '/dist/index.html'));

Adding these two lines in server.js worked for me:在 server.js 中添加这两行对我有用:

var distDir = __dirname + "/dist/"; app.use(express.static(distDir));

My dist structure is as follows:我的dist结构如下:

在此处输入图片说明

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Digital Ocean Droplet 中部署 Strapi 时出错:因为它违反了以下内容安全策略指令:“connect-src &#39;self&#39; https: - Errors deploying Strapi in Digital Ocean Droplet: because it violates the following Content Security Policy directive: "connect-src 'self' https: 拒绝连接到 x 因为它违反了以下内容安全策略指令 (connect-src) - Refused to connect to x because it violates the following Content Security Policy directive (connect-src) 拒绝执行内联脚本,因为它违反了以下内容安全策略指令:“script-src &#39;self&#39;”。? - Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'".? 拒绝加载图像'<url> ' 因为它违反了以下内容安全策略指令:“img-src 'self' data:”</url> - Refused to load the image '<URL>' because it violates the following Content Security Policy directive: "img-src 'self' data:" 尝试渲染iframe:祖先违反了以下内容安全策略指令:“frame-ancestors'none'” - Trying to render iframe: ancestor violates the following Content Security Policy directive: “frame-ancestors 'none'” create-react-app 问题:拒绝加载图像&#39;<URL> &#39; 因为它违反了以下内容安全策略指令: - create-react-app issue: Refused to load the image '<URL>' because it violates the following Content Security Policy directive: Cordova 错误:拒绝执行内联脚本,因为它违反了以下内容安全策略指令 - Cordova error: Refused to execute inline script because it violates the following Content Security Policy directive Iframe 抛出错误:拒绝帧,因为它违反了以下内容安全策略指令 - Iframe throw error: refused to frame because it violates the following content security policy directive 内容安全策略:页面设置阻止加载内联资源(“default-src”) - Content Security Policy: The page’s settings blocked the loading of a resource at inline (“default-src”) 内容安全策略:页面的设置阻止自行加载资源(“ default-src”) - Content Security Policy: The page’s settings blocked the loading of a resource at self (“default-src”)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM