我已經添加了頭盔功能來設置CPS,但是存在字體問題。一個簡單的例子如下:expressjs頭盔cps問題與字體
但是,它會正確加載所有資產,但它所抱怨的字體除外。
sample.css
src: url("/assets/fonts/font.eot")
Example.com
app.use(csp({
directives: {
defaultSrc: ["'self'"],
scriptSrc: ["'self'", "'unsafe-inline'"],
styleSrc: ["'self'", "'unsafe-inline'"],
imgSrc: ["'self'"],
fontSrc: ["'self'", "'unsafe-inline'"],
sandbox: ['allow-forms', 'allow-scripts'],
reportUri: '/report-violation',
objectSrc: [],
},
reportOnly: false,
setAllHeaders: false,
disableAndroid: false,
browserSniff: true
}));
,並在瀏覽器,它讓我對字體此錯誤消息
Font from origin 'http://localhost:3000' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
是我錯過了一些馬關於瀏覽器內的字體工作?
在表達我已確保公共和資產文件設置正確。 (從資產的一切工作正常)。
app.use("/assets", express.static(__dirname + "/assets"));
app.use("/public", express.static(__dirname + "/public"));
在這種情況下'__dirname'是什麼? – JoeKir