This commit is contained in:
parent
e37fbd129a
commit
b6f22fda2c
|
|
@ -10,12 +10,23 @@
|
||||||
let _env: Record<string, string> | null = null
|
let _env: Record<string, string> | null = null
|
||||||
|
|
||||||
export function getRuntimeEnv(key: string): string | undefined {
|
export function getRuntimeEnv(key: string): string | undefined {
|
||||||
// 强制每次从 window.RUNTIME_ENV 获取,而不依赖缓存
|
// 打印缓存的 _env 变量和每次调用时的 key
|
||||||
if (typeof window !== "undefined" && typeof window.RUNTIME_ENV !== "undefined") {
|
console.log("Checking env for key:", key);
|
||||||
_env = window.RUNTIME_ENV // 更新 _env,确保使用最新的环境变量
|
|
||||||
|
// 如果 _env 存在,打印出缓存的 _env 并返回对应的值
|
||||||
|
if (_env) {
|
||||||
|
console.log("Returning cached _env:", _env);
|
||||||
return _env[key]
|
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]
|
return process.env[key]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue