得到一个“违反了以下内容安全策略指令:” default
我正在尝试将我的角度应用程序部署到Heroku,但我遇到了很多问题。我收到错误消息“拒绝加载图像'.ico',因为它违反了以下内容安全策略指令”:“ default-src'none'”。请注意,未明确设置'img-src',因此' default-src'用作后备。”
我尝试添加http:// * https://*'unsafe-inline'; script-src'self'http://* https://*'unsafe-inline''unsafe-eval'“>到我的index.html,并且我尝试运行ng build,但没有解决任何问题
不确定该错误来自我的代码的哪里,但这是服务器的一部分
app.use(express.static(__dirname + '/dist'));
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
这里是我的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"
},
我尝试部署到角度服务器,我希望它启动我的服务器并加载我的静态角度文件,但是它在页面上显示了“内部服务器错误”,并显示了一个""Refused to load the image '.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.
任何帮助将不胜感激
回答如下:可能未正确给出路径。转到dist文件夹并检查index.html
的正确路径示例:
'/dist/**<your app name>**' && '/dist/**<your app name>**/index.html'
并在以下两行中更改路径
app.use(express.static(__dirname + '/dist'));
res.sendFile(path.join(__dirname + '/dist/index.html'));
得到一个“违反了以下内容安全策略指令:” default
我正在尝试将我的角度应用程序部署到Heroku,但我遇到了很多问题。我收到错误消息“拒绝加载图像'.ico',因为它违反了以下内容安全策略指令”:“ default-src'none'”。请注意,未明确设置'img-src',因此' default-src'用作后备。”
我尝试添加http:// * https://*'unsafe-inline'; script-src'self'http://* https://*'unsafe-inline''unsafe-eval'“>到我的index.html,并且我尝试运行ng build,但没有解决任何问题
不确定该错误来自我的代码的哪里,但这是服务器的一部分
app.use(express.static(__dirname + '/dist'));
app.get('/*', function(req, res) {
res.sendFile(path.join(__dirname + '/dist/index.html'));
});
这里是我的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"
},
我尝试部署到角度服务器,我希望它启动我的服务器并加载我的静态角度文件,但是它在页面上显示了“内部服务器错误”,并显示了一个""Refused to load the image '.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.
任何帮助将不胜感激
回答如下:可能未正确给出路径。转到dist文件夹并检查index.html
的正确路径示例:
'/dist/**<your app name>**' && '/dist/**<your app name>**/index.html'
并在以下两行中更改路径
app.use(express.static(__dirname + '/dist'));
res.sendFile(path.join(__dirname + '/dist/index.html'));