很棒的字体未加载,请帮忙。我需要使用很棒的字体图标,但出现此错误。 拒绝加载脚本“https://use.fontawesome.com/a780df76b3.js”,因为它违反了以下内容安全策略指令:“script-src 'self'”。请注意,“script-src-elem”未明确设置,因此“script-src”用作后备
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0" />
<meta name="google-site-verification" content="3WujPQ31psszBWWagcwEXBhSUGSZreEvBe4ax5T1i2E" />
<title>Authenticate</title>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@500&display=swap" rel="stylesheet" />
<style>
* {
font-family: "Montserrat", sans-serif;
}
.google {
margin-left: 630px;
margin-bottom: 100px;
margin-top: 80px;
}
.title {
font-family: "Montserrat", sans-serif;
}
.google{
margin: 0 auto;
color: #111
}
.github {
margin: 0 auto;
color: #111
}
</style>
<script defer src="https://use.fontawesome.com/a780df76b3.js"></script>
</head>
<body>
<h1 class="text-xl font-black my-9 text-center mx-auto title">
Authenticate to start using
</h1>
<a id="google-button" class="btn btn-block btn-social btn-google google" href="/auth/google/">
<i class="fa fa-google"></i> Login with Google
</a>
<!--Github-->
<a id="github-button" class="btn btn-block btn-social btn-github github" href="/auth/github/">
<i class="fa fa-github"></i> Login with GitHub
</a>
</body>
</html>
正如您在“运行代码片段”中看到的,您的代码在这里运行良好。因此,原因在于您的网络服务器 - 它默认发布内容安全策略
"script-src 'self'"
。
只需将
https://use.fontawesome.com
主机源添加到 script-src
指令中:"script-src 'self' https://use.fontawesome.com"
。
或者如果您不知道 CSP 是什么,请关闭它。因为默认的 CSP 设置至少也会被阻止:
https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css
和 https://fonts.gstatic.com
指令中的 https://fonts.googleapis.com
、style-src
和 script-src
。
由于您没有指定用作服务器的内容,我将尝试猜测:Node.js + Helmet 4 来管理安全标头。
要禁用 Helmet 中的
contentSecurityPolicy
中间件但保留其余标头:
helmet({
contentSecurityPolicy: false,
})