| | | 1 | | /** Keys safe to display (no secrets); values still appear in HTML—keep the route gated. */ |
| | 0 | 2 | | const SERVER_DEBUG_ENV_KEYS = [ |
| | | 3 | | "ENABLE_DEBUG_CONFIG", |
| | | 4 | | "NODE_ENV", |
| | | 5 | | "SERVER_API_URL", |
| | | 6 | | "API_URL", |
| | | 7 | | "VITE_API_URL", |
| | | 8 | | "PUBLIC_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", |
| | | 9 | | "PUBLIC_OTEL_SERVICE_NAME", |
| | | 10 | | "VITE_OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", |
| | | 11 | | "VITE_OTEL_SERVICE_NAME", |
| | | 12 | | "OTEL_EXPORTER_OTLP_ENDPOINT", |
| | | 13 | | "OTEL_EXPORTER_OTLP_TRACES_ENDPOINT", |
| | | 14 | | "OTEL_EXPORTER_OTLP_METRICS_ENDPOINT", |
| | | 15 | | "OTEL_EXPORTER_OTLP_LOGS_ENDPOINT", |
| | | 16 | | "OTEL_EXPORTER_OTLP_PROTOCOL", |
| | | 17 | | "OTEL_SERVICE_NAME", |
| | | 18 | | "OTEL_SDK_DISABLED", |
| | | 19 | | "OTEL_RESOURCE_ATTRIBUTES", |
| | | 20 | | ] as const; |
| | | 21 | | |
| | 0 | 22 | | export function isDebugConfigAllowed(): boolean { |
| | 0 | 23 | | if (import.meta.env.DEV) return true; |
| | 0 | 24 | | return process.env.ENABLE_DEBUG_CONFIG === "true"; |
| | | 25 | | } |
| | | 26 | | |
| | 0 | 27 | | export function pickDebugServerEnv(): Record<string, string> { |
| | 0 | 28 | | const out: Record<string, string> = {}; |
| | 0 | 29 | | for (const key of SERVER_DEBUG_ENV_KEYS) { |
| | 0 | 30 | | out[key] = process.env[key] ?? ""; |
| | | 31 | | } |
| | 0 | 32 | | return out; |
| | | 33 | | } |
| | | 34 | | |
| | 0 | 35 | | function stringifyEnvValue(value: unknown): string { |
| | 0 | 36 | | if (value === null || value === undefined) return ""; |
| | 0 | 37 | | if ( |
| | | 38 | | typeof value === "string" || |
| | | 39 | | typeof value === "number" || |
| | | 40 | | typeof value === "boolean" |
| | | 41 | | ) { |
| | 0 | 42 | | return String(value); |
| | | 43 | | } |
| | 0 | 44 | | return JSON.stringify(value); |
| | | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | export function pickImportMetaEnvForDebug(): Record<string, string> { |
| | 0 | 48 | | const env = import.meta.env as Record<string, unknown>; |
| | 0 | 49 | | const out: Record<string, string> = {}; |
| | 0 | 50 | | for (const key of Object.keys(env).sort((a, b) => a.localeCompare(b, "en"))) { |
| | 0 | 51 | | out[key] = stringifyEnvValue(env[key]); |
| | | 52 | | } |
| | 0 | 53 | | return out; |
| | | 54 | | } |