feat: validate all required env vars at startup
This commit is contained in:
parent
255518a6a8
commit
1875f16d48
1 changed files with 19 additions and 4 deletions
|
|
@ -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)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue