From 00c5616eada091f7ee688af84b85213fc925f5af Mon Sep 17 00:00:00 2001 From: devinxl Date: Mon, 4 Nov 2024 12:03:32 +0800 Subject: [PATCH] fix(dcellar-web-ui): fix middleware not working --- apps/dcellar-web-ui/next.config.js | 3 +- apps/dcellar-web-ui/src/base/env.ts | 2 +- .../src/components/common/Ga4/index.tsx | 11 +++- apps/dcellar-web-ui/src/middleware.ts | 58 +++++++++++++++++++ apps/dcellar-web-ui/src/pages/_document.tsx | 51 ++++++++++++---- apps/dcellar-web-ui/tsconfig.json | 2 +- 6 files changed, 110 insertions(+), 17 deletions(-) create mode 100644 apps/dcellar-web-ui/src/middleware.ts diff --git a/apps/dcellar-web-ui/next.config.js b/apps/dcellar-web-ui/next.config.js index aeb6695a..592bb6b7 100644 --- a/apps/dcellar-web-ui/next.config.js +++ b/apps/dcellar-web-ui/next.config.js @@ -72,7 +72,8 @@ const nextConfig = { reactStrictMode: false, distDir: '.next', webpack, - assetPrefix: process.env.NODE_ENV === 'production' ? '/static/dcellar-web-ui' : '', + // assetPrefix: process.env.NODE_ENV === 'production' ? '/static/dcellar-web-ui' : '', + assetPrefix: '', pageExtensions: ['mdx', 'jsx', 'js', 'ts', 'tsx'], generateBuildId: async () => { return commitHash; diff --git a/apps/dcellar-web-ui/src/base/env.ts b/apps/dcellar-web-ui/src/base/env.ts index d86a6345..908cd3db 100644 --- a/apps/dcellar-web-ui/src/base/env.ts +++ b/apps/dcellar-web-ui/src/base/env.ts @@ -1,7 +1,7 @@ import { removeTrailingSlash } from '@/utils/string'; import getConfig from 'next/config'; -const { publicRuntimeConfig, serverRuntimeConfig } = getConfig(); +const { publicRuntimeConfig, serverRuntimeConfig } = getConfig() || {}; const { NEXT_PUBLIC_ENV, NEXT_PUBLIC_STATIC_HOST, diff --git a/apps/dcellar-web-ui/src/components/common/Ga4/index.tsx b/apps/dcellar-web-ui/src/components/common/Ga4/index.tsx index f47f49a9..167378fd 100644 --- a/apps/dcellar-web-ui/src/components/common/Ga4/index.tsx +++ b/apps/dcellar-web-ui/src/components/common/Ga4/index.tsx @@ -1,14 +1,19 @@ +import Script from 'next/script'; + interface IGtag { id: string; disabled?: boolean; + nonce?: string; } -export const Ga4 = ({ id, disabled }: IGtag) => { +export const Ga4 = ({ id, disabled, nonce }: IGtag) => { if (disabled) return null; return ( <> - - - - + /> + + + diff --git a/apps/dcellar-web-ui/tsconfig.json b/apps/dcellar-web-ui/tsconfig.json index c2e5cfc2..0e02af77 100644 --- a/apps/dcellar-web-ui/tsconfig.json +++ b/apps/dcellar-web-ui/tsconfig.json @@ -21,6 +21,6 @@ "@/public/*": ["public/*"] } }, - "include": ["next-env.d.ts", "typings.d.ts", "**/*.ts", "**/*.tsx"], + "include": ["next-env.d.ts", "typings.d.ts", "**/*.ts", "**/*.tsx", "src/middleware.ts"], "exclude": ["node_modules", ".next"] }