如何修复内容安全策略错误节点应用程序
How to fix Content Security Policy error Node app
const express = require('express');
const graphqlHTTP = require('express-graphql');
const schema = require('./schema/schema');
const app = express();
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
}));
app.listen(5000, () => {
console.log('now listening for requests on port 5000')
})
GET http://localhost:5000/ 404(未找到)
localhost/:1 拒绝加载图像“http://localhost:5000/favicon.ico”,因为它违反了以下内容安全策略指令:"default-src 'none'"。请注意,'img-src' 未明确设置,因此 'default-src' 用作后备。
I'm getting a "content security policy error on my node app. I'm only running a simple node server app. I added a favicon.ico image in the root folder as per the error message request , but it doesn't go away.
快速服务器不会自动提供源目录中的文件。如果您希望 /favicon.ico
请求提供您的文件,您需要向服务器添加适当的逻辑:
const path = require('path');
app.get('/favicon.ico', (req, res) => {
// Use actual relative path to your .ico file here
res.sendFile(path.resolve(__dirname, '../favicon.ico'));
});
const express = require('express');
const graphqlHTTP = require('express-graphql');
const schema = require('./schema/schema');
const app = express();
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
}));
app.listen(5000, () => {
console.log('now listening for requests on port 5000')
})
GET http://localhost:5000/ 404(未找到)
localhost/:1 拒绝加载图像“http://localhost:5000/favicon.ico”,因为它违反了以下内容安全策略指令:"default-src 'none'"。请注意,'img-src' 未明确设置,因此 'default-src' 用作后备。
快速服务器不会自动提供源目录中的文件。如果您希望 /favicon.ico
请求提供您的文件,您需要向服务器添加适当的逻辑:
const path = require('path');
app.get('/favicon.ico', (req, res) => {
// Use actual relative path to your .ico file here
res.sendFile(path.resolve(__dirname, '../favicon.ico'));
});