Skip to content

Validate required environment variables at startup and document per-network config #9

Description

@priscaenoch

Problem

.env.example defines large per-network variable groups (TESTNET_*, MAINNET_*, DEVNET_* for database, read replica, RPC, RPC WS, Horizon, passphrase, API subdomain) plus indexer tuning vars. There is no fail-fast validation, so a missing or misnamed variable surfaces as a deep runtime error on the first request that needs it rather than at boot. zod is already a dependency and is well suited to this.

What needs to be done

  • Add a startup config validator (using zod) that checks all required variables for the selected network (STELLAR_NETWORK/NODE_ENV) and exits with a clear message listing missing/invalid vars.
  • Apply it to both the API service (src/index.ts) and the indexer entrypoint.
  • Document the required variables per network in the README, and confirm the TESTNET_* set matches the live testnet deployment.

Files

  • new src/config/validateEnv.ts (and indexer equivalent)
  • src/index.ts, indexer/src/index.js/config.js
  • .env.example, README.md

Acceptance deliverables

  • Starting either service with a missing required variable fails immediately with a clear, actionable message.
  • README documents required variables per network.

Tests to pass

  • Unit test: validator passes with a complete env and throws listing the missing keys with an incomplete env.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial Campaign | FWC26Campaign: Official Campaign | FWC26enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions