问题描述
我目前正在使用 react 开发 SPA。为了为 SPA 提供服务,我只有一个快速服务器,它将构建文件夹作为静态文件夹提供服务。
但是每当我尝试运行应用程序时,什么都没有加载,并且出现控制台错误:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword,a hash ('sha256-1kri9uKG6Gd9VbixGzyFE/kaQIHihYFdxFKKhgz3b80='),or a nonce ('nonce-...') is required to enable inline execution.
我已经用谷歌搜索了很多,但我找不到任何有用的东西。
我已尝试禁用头盔 CSP,但仍然出现错误。
我试过卸载头盔,没有。
停止并重新启动服务器,不。
停止一切,重新启动服务器并重新打开 chrome,不。
目前这是我的使用声明
App.use(helmet({
contentSecurityPolicy: {
directives: {
defaultSrc: ["'self'"],scriptSrc: ["'self'","'unsafe-inline'",'https://ajax.googleapis.com','https://stackpath.bootstrapcdn.com'],styleSrc: ["'self'"],imgSrc: ["*",'data:'],connectSrc: ["'self'"],frameSrc: ["'self'"],},}
}));
因为无论我假设 CSP 没有更新,它都是相同的错误,但我不知道足以测试这个理论,或者我什至不能做些什么来纠正它。
解决方法
在阅读头盔维护者 Evan Hahn 的评论后,我用谷歌搜索记住了快捷方式,然后就去网站按 ctrl-F5 刷新页面并同时清除缓存,就像一个魅力。