From 1875f16d4856d910fc4c69c1ae2092c2423ba326 Mon Sep 17 00:00:00 2001 From: Jennie Robinson Faber Date: Sat, 4 Apr 2026 12:34:49 +0100 Subject: [PATCH] feat: validate all required env vars at startup --- server/plugins/validate-env.js | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/server/plugins/validate-env.js b/server/plugins/validate-env.js index 886ae6e..9f4b363 100644 --- a/server/plugins/validate-env.js +++ b/server/plugins/validate-env.js @@ -1,9 +1,24 @@ export default defineNitroPlugin(() => { - const config = useRuntimeConfig() + const required = [ + 'MONGODB_URI', + 'JWT_SECRET', + 'RESEND_API_KEY', + 'HELCIM_API_TOKEN', + 'NUXT_PUBLIC_HELCIM_TOKEN', + ] - if (!config.jwtSecret) { - console.error('FATAL: JWT_SECRET environment variable is not set. Server cannot start without it.') - console.error('Set JWT_SECRET in your .env file or environment variables.') + const missing = required.filter((key) => { + // Check both process.env and runtime config where applicable + if (key === 'JWT_SECRET') { + const config = useRuntimeConfig() + return !config.jwtSecret + } + return !process.env[key] + }) + + if (missing.length > 0) { + console.error(`FATAL: Missing required environment variables: ${missing.join(', ')}`) + console.error('Set these in your .env file or environment variables.') process.exit(1) } })