[英]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'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.