feat: support csp (#9111)

Co-authored-by: Joel <iamjoel007@gmail.com>
This commit is contained in:
NFish 2024-10-11 16:14:56 +08:00 • committed by GitHub
commit f4ce08211d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 148 additions and 62 deletions

View file

@ -1,6 +1,7 @@
import type { FC } from 'react'
import React from 'react'
import Script from 'next/script'
import { headers } from 'next/headers'
import { IS_CE_EDITION } from '@/config'
export enum GaType {
@ -23,9 +24,16 @@ const GA: FC<IGAProps> = ({
if (IS_CE_EDITION)
return null
const nonce = process.env.NODE_ENV === 'production' ? headers().get('x-nonce') : ''
return (
<>
<Script strategy="beforeInteractive" async src={`https://www.googletagmanager.com/gtag/js?id=${gaIdMaps[gaType]}`}></Script>
<Script
strategy="beforeInteractive"
async
src={`https://www.googletagmanager.com/gtag/js?id=${gaIdMaps[gaType]}`}
nonce={nonce!}
></Script>
<Script
id="ga-init"
dangerouslySetInnerHTML={{
@ -36,6 +44,7 @@ gtag('js', new Date());
gtag('config', '${gaIdMaps[gaType]}');
`,
}}
nonce={nonce!}
>
</Script>
</>

View file

@ -1,16 +0,0 @@
'use client'
import { AppProgressBar as ProgressBar } from 'next-nprogress-bar'
const Topbar = () => {
return (
<>
<ProgressBar
height='2px'
color="#1C64F2FF"
options={{ showSpinner: false }}
shallowRouting />
</>)
}
export default Topbar