Skip to content

Fail the build when NEXT_PUBLIC_API_URL is missing or invalid - #434

Merged
0xdevcollins merged 2 commits into
boundlessfi:mainfrom
olufunsoolutayo:API
Oct 22, 2026
Merged

0xdevcollins merged 2 commits into
boundlessfi:mainfrom
olufunsoolutayo:API

Conversation

@olufunsoolutayo

@olufunsoolutayo olufunsoolutayo commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Closes #406

What changed

  • lib/env.ts validates the public environment once, at import time:
    • NEXT_PUBLIC_API_URL is required and must be an absolute http(s) URL.
    • NEXT_PUBLIC_SITE_URL and NEXT_PUBLIC_BOUNDLESS_APP_URL are optional (they keep their fallbacks in lib/seo/site.ts), but must be absolute http(s) URLs when set.
    • Any problem throws one message that names every bad variable and says to copy .env.example to .env.local.
  • next.config.ts imports it, so both next build and next dev fail before compiling anything.
  • lib/api/client.ts and lib/seo/site.ts read the values from publicEnv, so lib/env.ts is the only file that reads process.env.NEXT_PUBLIC_*. Trailing-slash trimming is unchanged.

Verification

Case Result
npm run build with NEXT_PUBLIC_API_URL unset fails, exit 1, names NEXT_PUBLIC_API_URL
NEXT_PUBLIC_API_URL=not-a-url npm run build fails the same way
NEXT_PUBLIC_SITE_URL=ftp://x, NEXT_PUBLIC_BOUNDLESS_APP_URL=nope fails, names both
npm run build with the .env.example values passes
npm run dev without the variable exits at startup with the same message
Error: Invalid or missing public environment variable(s): NEXT_PUBLIC_API_URL. Copy .env.example to .env.local and set each URL to an absolute http(s) URL.

npm run lint, npx tsc --noEmit, npm run build and npm run seo:check pass. The API origin is inlined into the client bundle and no chunk reads process.env at runtime.

@drips-wave

drips-wave Bot commented Oct 20, 2026

Copy link
Copy Markdown

@olufunsoolutayo 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

@vercel

vercel Bot commented Oct 20, 2026

Copy link
Copy Markdown

@olufunsoolutayo is attempting to deploy a commit to the Threadflow Team on Vercel.

A member of the Team first needs to authorize it.

- Narrow apiUrl by checking it in the failure guard instead of casting it
  with `as string`.
- Import the env module as @/lib/env like the rest of lib/ (next.config.ts
  keeps its relative import, since the alias is not available there).
- Add the missing trailing newline to lib/env.ts.
@0xdevcollins
0xdevcollins merged commit 6a6ebf1 into boundlessfi:main Oct 22, 2026
1 check failed
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.

Fail the build when NEXT_PUBLIC_API_URL is missing or invalid

2 participants