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.
Harden API base configuration with explicit env validation
Description
Both
src/lib/apiClient.tsandsrc/app/quote/page.tsxreadprocess.env.NEXT_PUBLIC_STABLEROUTE_API_BASEand silently fall back tohttp://localhost:3001. A typo or missing prod value ships a build that quietly points at localhost, and anhttp://value downgrades transport in production. This issue centralizes and validates the API base.Requirements and context
src/lib/env.tsthat reads, trims, and validates the API base (must be a valid absolute URL; warn or throw ifhttp:is used outside development).apiClient.tsandquote/page.tsxconsume it instead of readingprocess.envdirectly..env.exampledocumentingNEXT_PUBLIC_STABLEROUTE_API_BASEwith a safe placeholder.Suggested execution
git checkout -b security/config-21-env-validationsrc/lib/env.ts; updatesrc/lib/apiClient.tsandsrc/app/quote/page.tsx.src/lib/__tests__/env.test.tscovering valid/invalid/missing values.README.mdand add.env.example.Test and commit
npm run lint,npm test, andnpm run build.npm testoutput in the PR description.Example commit message
security: centralize and validate NEXT_PUBLIC_STABLEROUTE_API_BASEGuidelines
Community & contribution rewards