refactor(env): unify required-env validation through useRuntimeConfig
validate-env.js now reads all four required vars (MONGODB_URI, JWT_SECRET, RESEND_API_KEY, HELCIM_API_TOKEN) from useRuntimeConfig() instead of mixing direct process.env reads with a JWT-only special case. Mongoose and the six Resend instantiations follow suit. Either bare or NUXT_-prefixed env names are accepted, so Dokploy no longer needs duplicate entries.
This commit is contained in:
parent
1083a1d260
commit
04eb33df6e
9 changed files with 17 additions and 24 deletions
|
|
@ -1,23 +1,17 @@
|
|||
export default defineNitroPlugin(() => {
|
||||
const required = [
|
||||
'MONGODB_URI',
|
||||
'JWT_SECRET',
|
||||
'RESEND_API_KEY',
|
||||
'HELCIM_API_TOKEN',
|
||||
]
|
||||
const config = useRuntimeConfig()
|
||||
const checks = {
|
||||
MONGODB_URI: config.mongodbUri,
|
||||
JWT_SECRET: config.jwtSecret,
|
||||
RESEND_API_KEY: config.resendApiKey,
|
||||
HELCIM_API_TOKEN: config.helcimApiToken,
|
||||
}
|
||||
|
||||
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]
|
||||
})
|
||||
const missing = Object.entries(checks).filter(([, value]) => !value).map(([key]) => 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.')
|
||||
console.error('Set these (or their NUXT_-prefixed equivalents) in your .env file or environment variables.')
|
||||
process.exit(1)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue