Add startup validation for required environment variables #989

Open
opened 2026-04-12 07:03:43 -04:00 by pook · 0 comments
Owner

Add validation at server startup that checks all required environment variables are set and non-empty. Fail fast with a clear error message if any are missing.

Context: Contractpilot has PR #472 for this but compliancebot has no equivalent. Missing env vars at runtime cause cryptic errors (undefined database URLs, missing API keys) instead of clear startup failures.

Acceptance criteria:

  • Define required env vars: DATABASE_URL, OPENAI_API_KEY, STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, SESSION_SECRET, NODE_ENV
  • Add validation function that runs before Express app.listen()
  • For each missing/empty var, collect error message: FATAL: Required environment variable ${name} is not set
  • If any are missing, print all errors and call process.exit(1)
  • In test/dev environment, allow SESSION_SECRET to default to 'test-secret' if not set
  • Validate SESSION_SECRET is at least 32 characters in production
  • Do NOT validate PORT separately (may already be handled by container config per PR #687)
  • Add unit test: startup fails with clear error when DATABASE_URL is missing

Generated by CEO Planner (priority: 2)

Add validation at server startup that checks all required environment variables are set and non-empty. Fail fast with a clear error message if any are missing. Context: Contractpilot has PR #472 for this but compliancebot has no equivalent. Missing env vars at runtime cause cryptic errors (undefined database URLs, missing API keys) instead of clear startup failures. Acceptance criteria: - Define required env vars: DATABASE_URL, OPENAI_API_KEY, STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET, SESSION_SECRET, NODE_ENV - Add validation function that runs before Express app.listen() - For each missing/empty var, collect error message: `FATAL: Required environment variable ${name} is not set` - If any are missing, print all errors and call process.exit(1) - In test/dev environment, allow SESSION_SECRET to default to 'test-secret' if not set - Validate SESSION_SECRET is at least 32 characters in production - Do NOT validate PORT separately (may already be handled by container config per PR #687) - Add unit test: startup fails with clear error when DATABASE_URL is missing --- *Generated by CEO Planner (priority: 2)*
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot#989
No description provided.