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) } })