refactor: modify getEnv to return undefined for non-existent environment variables

This commit is contained in:
hamster1963 2025-01-30 00:48:48 +08:00
parent d775cde3ca
commit 4da2eca1c1

View File

@ -1,7 +1,7 @@
import { getClientEnv, getServerEnv } from "./env" import { getClientEnv, getServerEnv } from "./env"
import type { EnvKey } from "./env" import type { EnvKey } from "./env"
export default function getEnv(key: EnvKey): string { export default function getEnv(key: EnvKey): string | undefined {
if (key.startsWith("NEXT_PUBLIC_")) { if (key.startsWith("NEXT_PUBLIC_")) {
const clientKey = key.replace("NEXT_PUBLIC_", "") as any const clientKey = key.replace("NEXT_PUBLIC_", "") as any
return getClientEnv(clientKey) return getClientEnv(clientKey)