Skip to content

Validate the NEXT_PUBLIC_STABLEROUTE_API_BASE environment variable at startup #21

Description

@mikewheeleer

Harden API base configuration with explicit env validation

Description

Both src/lib/apiClient.ts and src/app/quote/page.tsx read process.env.NEXT_PUBLIC_STABLEROUTE_API_BASE and silently fall back to http://localhost:3001. A typo or missing prod value ships a build that quietly points at localhost, and an http:// value downgrades transport in production. This issue centralizes and validates the API base.

Requirements and context

  • Repository scope: StableRoute-Org/Stableroute-frontend only.
  • Create src/lib/env.ts that reads, trims, and validates the API base (must be a valid absolute URL; warn or throw if http: is used outside development).
  • Re-export the validated base and have apiClient.ts and quote/page.tsx consume it instead of reading process.env directly.
  • Add an .env.example documenting NEXT_PUBLIC_STABLEROUTE_API_BASE with a safe placeholder.
  • Fail loudly in production builds when the value is missing/invalid, but keep the localhost dev fallback.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b security/config-21-env-validation
  • Implement changes
  • Test and commit

Test and commit

  • Run npm run lint, npm test, and npm run build.
  • Cover edge cases: missing var, valid https, http in dev vs prod, and trailing-slash normalization.
  • Include the full npm test output in the PR description.

Example commit message

security: centralize and validate NEXT_PUBLIC_STABLEROUTE_API_BASE

Guidelines

  • Minimum 95 percent test coverage for impacted modules.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the StableRoute community on Discord for questions, reviews, and faster merges: https://discord.gg/37aCpusvx
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions