Files
FarmaFinder/apps/backend/src/config/required-env.js
T
Antoni Nuñez Romeu 849763896d
Run Tests on Branches / Detect Changes (push) Successful in 12s
Run Tests on Branches / Frontend Tests (push) Successful in 2m12s
Run Tests on Branches / Frontend Mobile Tests (push) Has been skipped
Run Tests on Branches / Parapharmacy API Tests (push) Successful in 2m2s
Run Tests on Branches / PIP Platform Tests (push) Has been skipped
Run Tests on Branches / Backend Tests (push) Successful in 2m8s
security: harden production configuration and routes
2026-07-22 17:24:54 +02:00

31 lines
914 B
JavaScript

const PLACEHOLDERS = new Set([
'',
'change-me-in-production',
'farma-clic-secret-key-change-in-production',
'replace-me',
'dev-ingest-key-change-me',
])
export function validateProductionEnv(env = process.env) {
if (env.NODE_ENV !== 'production') return
const required = [
['SESSION_SECRET', env.SESSION_SECRET],
['CORS_ORIGIN', env.CORS_ORIGIN],
]
for (const [name, value] of required) {
if (!value || PLACEHOLDERS.has(value)) {
throw new Error(`${name} must be set to a non-placeholder value in production`)
}
}
if (env.CORS_ORIGIN.includes('localhost') || env.CORS_ORIGIN.includes('127.0.0.1')) {
throw new Error('CORS_ORIGIN must not point to localhost in production')
}
if (!env.PG_URL && (!env.PG_PASSWORD || PLACEHOLDERS.has(env.PG_PASSWORD))) {
throw new Error('PG_URL or PG_PASSWORD must be set to a non-placeholder value in production')
}
}