From 3c13ff0fef2ac12131d583d8473bfbeb7930ca65 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Wed, 25 Sep 2024 15:57:59 +0800 Subject: [PATCH 1/2] feat: disablePrefetch config --- .env.example | 1 + app/(main)/page.tsx | 13 ++++++++++--- docker/.env.example | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 7d597d9ef..b64cef0a6 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ NezhaBaseUrl=http://1.1.1.1:8008 NezhaAuth=nezha-token +ServerDisablePrefetch=false NEXT_PUBLIC_NezhaFetchInterval=2000 NEXT_PUBLIC_ShowFlag=true NEXT_PUBLIC_DisableCartoon=false \ No newline at end of file diff --git a/app/(main)/page.tsx b/app/(main)/page.tsx index 24a1a48dc..86719a1a7 100644 --- a/app/(main)/page.tsx +++ b/app/(main)/page.tsx @@ -1,16 +1,23 @@ import ServerList from "@/components/ServerList"; import ServerOverview from "@/components/ServerOverview"; +import getEnv from "@/lib/env-entry"; import { GetNezhaData } from "@/lib/serverFetch"; import { SWRConfig } from "swr"; +const disablePrefetch = getEnv("ServerDisablePrefetch") === "true"; + +const fallback = disablePrefetch + ? {} + : { + "/api/server": GetNezhaData(), + }; + export default function Home() { return (
diff --git a/docker/.env.example b/docker/.env.example index b452c5f40..b8114217d 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -1,5 +1,6 @@ NezhaBaseUrl=http://0.0.0.0:8008 NezhaAuth=5hAY3QX6Nl9B3UOQgB26KdsdS1dsdUdM +ServerDisablePrefetch=false NEXT_PUBLIC_NezhaFetchInterval=5000 NEXT_PUBLIC_ShowFlag=true NEXT_PUBLIC_DisableCartoon=true \ No newline at end of file From c5b96d18ac400105d08a474b81d3b00852a2bd0a Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Wed, 25 Sep 2024 16:07:45 +0800 Subject: [PATCH 2/2] doc: add ServerDisablePrefetch config --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 3e04e8d69..6b89d819b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,7 @@ | ------------------------------ | -------------------- | -------------------------------- | | NezhaBaseUrl | nezha 面板地址 | http://120.x.x.x:8008 | | NezhaAuth | nezha 面板 API Token | 5hAY3QX6Nl9B3Uxxxx26KMvOMyXS1Udi | +| ServerDisablePrefetch | 是否禁用预加载 | **默认**:false | | NEXT_PUBLIC_NezhaFetchInterval | 获取数据间隔(毫秒) | **默认**:2000 | | NEXT_PUBLIC_ShowFlag | 是否显示旗帜 | **默认**:false | | NEXT_PUBLIC_DisableCartoon | 是否禁用卡通人物 | **默认**:false |