From b6f22fda2ce6d3e36741e3d1391764466309a46b Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 20 May 2025 22:35:11 +0800 Subject: [PATCH] . --- chatdesk-ui/lib/ipconfig.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/chatdesk-ui/lib/ipconfig.ts b/chatdesk-ui/lib/ipconfig.ts index d9f6350..9c18cda 100644 --- a/chatdesk-ui/lib/ipconfig.ts +++ b/chatdesk-ui/lib/ipconfig.ts @@ -10,12 +10,23 @@ let _env: Record | null = null export function getRuntimeEnv(key: string): string | undefined { - // 强制每次从 window.RUNTIME_ENV 获取,而不依赖缓存 - if (typeof window !== "undefined" && typeof window.RUNTIME_ENV !== "undefined") { - _env = window.RUNTIME_ENV // 更新 _env,确保使用最新的环境变量 + // 打印缓存的 _env 变量和每次调用时的 key + console.log("Checking env for key:", key); + + // 如果 _env 存在,打印出缓存的 _env 并返回对应的值 + if (_env) { + console.log("Returning cached _env:", _env); return _env[key] } - // 如果没有 window.RUNTIME_ENV,回退到 process.env + // 如果 window.RUNTIME_ENV 存在,打印出从 window.RUNTIME_ENV 获取的值 + if (typeof window !== "undefined" && typeof window.RUNTIME_ENV !== "undefined") { + _env = window.RUNTIME_ENV // 更新 _env 为最新的环境变量 + console.log("Updated _env from window.RUNTIME_ENV:", _env); + return _env[key] + } + + // 如果没有 window.RUNTIME_ENV,回退到 process.env,打印出 process.env 和当前 key + console.log("Falling back to process.env for key:", key); return process.env[key] }