This commit is contained in:
hailin 2025-06-25 16:32:26 +08:00
parent 87ec871a4b
commit 402779994e
1 changed files with 14 additions and 3 deletions

View File

@ -1,5 +1,16 @@
// lib/get-runtime-env.ts // lib/get-runtime-env.ts
export function getRuntimeEnv(key: string): string | undefined { export function getRuntimeEnv(key: string): string | undefined {
if (typeof window === "undefined") return process.env[key]; // SSR fallback /* ---------- 服务器端 (SSR) ---------- */
return (window as any).RUNTIME_ENV?.[key]; if (typeof window === "undefined") {
} const val = process.env[key]
console.log(`[getRuntimeEnv][SSR] key=${key} -> ${val ?? "undefined"} (process.env)`)
return val
}
/* ---------- 客户端 (CSR) ---------- */
const val = (window as any).RUNTIME_ENV?.[key]
console.log(
`[getRuntimeEnv][CSR] key=${key} -> ${val ?? "undefined"} (window.RUNTIME_ENV)`
)
return val
}