From 407b2227b3408f52eb3543d0e8f80ec07d9c8c64 Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Wed, 28 Jan 2026 01:00:30 +0100 Subject: [PATCH] env --- instrumentation.ts | 3 +++ lib/config.ts | 10 +++++++--- lib/services/create-services.server.ts | 3 --- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/instrumentation.ts b/instrumentation.ts index ae714898..2ad52569 100644 --- a/instrumentation.ts +++ b/instrumentation.ts @@ -13,6 +13,9 @@ export async function register() { // Initialize server services on boot // We do this AFTER Sentry to ensure errors during service init are caught + const { validateConfig } = await import('@/lib/config'); + validateConfig(); + const { getServerAppServices } = await import('@/lib/services/create-services.server'); getServerAppServices(); } diff --git a/lib/config.ts b/lib/config.ts index df5a9639..83f58c58 100644 --- a/lib/config.ts +++ b/lib/config.ts @@ -32,7 +32,7 @@ const getEnv = (key: string, defaultValue?: string): string | undefined => { (trimmed.startsWith('"') && trimmed.endsWith('"'))) { return trimmed.slice(1, -1); } - if (trimmed !== '') return trimmed; + return trimmed; } return defaultValue; @@ -141,8 +141,12 @@ export function validateConfig() { ]; for (const key of required) { - if (!getEnv(key)) { - throw new Error(`Missing required environment variable: ${key}`); + const value = getEnv(key); + if (!value) { + // In Next.js, process.env might not be a real object with enumerable keys in the bundle + // so we check the specific key directly + const rawValue = process.env[key]; + throw new Error(`Missing required environment variable: ${key}. (getEnv: "${value}", process.env: "${rawValue}"). If this is set in your environment, ensure it is not being shadowed or cleared by the container runtime.`); } } } diff --git a/lib/services/create-services.server.ts b/lib/services/create-services.server.ts index b1960242..91b50848 100644 --- a/lib/services/create-services.server.ts +++ b/lib/services/create-services.server.ts @@ -7,9 +7,6 @@ import { GlitchtipErrorReportingService } from './errors/glitchtip-error-reporti import { NoopErrorReportingService } from './errors/noop-error-reporting-service'; import { PinoLoggerService } from './logging/pino-logger-service'; import { config, getMaskedConfig, validateConfig } from '../config'; -// Validate configuration on server startup -validateConfig(); - let singleton: AppServices | undefined; export function getServerAppServices(): AppServices {