mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-04 19:21:51 +00:00
853610bbbf
Co-authored-by: Pablo F.G <pablo.fernandez@prowler.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
22 lines
989 B
TypeScript
22 lines
989 B
TypeScript
// Reads a runtime env var, with an optional deprecated-name fallback.
|
|
//
|
|
// Both names are read through a computed key (never a literal `process.env.X`
|
|
// member access) so Next.js/Turbopack does NOT inline them at build time. This
|
|
// is essential for the legacy `NEXT_PUBLIC_*` names: a literal read would be
|
|
// replaced with the build-time snapshot, defeating the runtime fallback. The
|
|
// new `UI_*` names are not `NEXT_PUBLIC_`-prefixed, so they are runtime reads
|
|
// regardless. Empty/whitespace values are treated as unset so a leftover empty
|
|
// `UI_*` still falls through to a configured legacy var.
|
|
const clean = (value?: string): string | null =>
|
|
value && value.trim() !== "" ? value : null;
|
|
|
|
export function readEnv(
|
|
primary: keyof NodeJS.ProcessEnv,
|
|
legacy?: keyof NodeJS.ProcessEnv,
|
|
): string | null {
|
|
const env = typeof process === "undefined" ? undefined : process.env;
|
|
if (!env) return null;
|
|
|
|
return clean(env[primary]) ?? (legacy ? clean(env[legacy]) : null);
|
|
}
|