Skip to content

feat: add environment configuration and validation with Zod (#2)#166

Merged
greatest0fallt1me merged 3 commits intoCalloraOrg:mainfrom
temisan0x:feature/env-config
Mar 27, 2026
Merged

feat: add environment configuration and validation with Zod (#2)#166
greatest0fallt1me merged 3 commits intoCalloraOrg:mainfrom
temisan0x:feature/env-config

Conversation

@temisan0x
Copy link
Copy Markdown
Contributor

Closes #2

What Changed

  • Added src/config/env.ts with a Zod schema that validates environment variables at startup and exits with clear field-level errors when validation fails.
  • Updated src/config/index.ts to import validated values from env.ts and export a typed config object.
  • Updated src/config/health.ts to use validated env values instead of raw process.env.
  • Updated src/index.ts to use config for PORT, UPSTREAM_URL, and PROXY_TIMEOUT_MS.
  • Added .env.example with all supported environment variables and placeholder values.
  • Updated README.md with a full environment variable table (required/optional, defaults, and descriptions).
  • Updated .gitignore to keep .env ignored while allowing .env.example to be committed (!.env.example).

Validation Behavior

  • Required vars fail fast on boot:
    • JWT_SECRET
    • ADMIN_API_KEY
    • METRICS_API_KEY
  • Conditional requirements fail fast on boot:
    • SOROBAN_RPC_ENABLED=true requires SOROBAN_RPC_URL
    • HORIZON_ENABLED=true requires HORIZON_URL

Testing

  • Missing required vars -> app exits immediately with clear validation errors listing each missing field.
  • Enabled optional integrations without required URLs -> app exits immediately with clear conditional validation errors.
  • Valid env (from .env / DOTENV_CONFIG_PATH) -> app starts cleanly on the configured port.

Scope Note

  • Existing process.env usage outside the env-config scope of this issue was intentionally left unchanged.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 26, 2026

@temisan0x Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me greatest0fallt1me merged commit d33a803 into CalloraOrg:main Mar 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Environment Configuration and Validation

2 participants