Skip to content

fix(cli): seed /api client URLs for combined Vercel deploys - #1242

Open
kzndotsh wants to merge 1 commit into
AmanVarshney01:mainfrom
kzndotsh:fix/vercel-client-server-url-1237
Open

kzndotsh wants to merge 1 commit into
AmanVarshney01:mainfrom
kzndotsh:fix/vercel-client-server-url-1237

Conversation

@kzndotsh

@kzndotsh kzndotsh commented Sep 15, 2026 •

Copy link
Copy Markdown

Summary

  • Combined Vercel web+server stacks now seed VITE_SERVER_URL=/api in apps/web/.env and .env.schema instead of http://localhost:3000.
  • Generated getServerUrl accepts a missing env value and falls back to /api, so module load no longer crashes on url.endsWith.
  • This matches the existing vercel.json buildCommand (VITE_SERVER_URL=/api) and same-origin /api rewrites.

Fixes #1237

Local dev. For Vercel-flagged stacks, bun run dev on the Vite port will request /api/trpc on the frontend origin. Use dev:vercel so vercel.json rewrites apply. Split web + server dev previously talked to http://localhost:3000.

Test plan

  • bun run check
  • cd apps/cli && bun run test (762 pass, 48 skip generated-build samples)
  • CLI + generator typechecks (check-types, check-test-types, packages/template-generator)
  • Regenerated TanStack Router + Vercel stack starts Vite with VITE_SERVER_URL=/api
  • CI generated-build shards

Summary by CodeRabbit

  • Bug Fixes
    • Improved generated deployment configuration for applications hosted on Vercel.
    • Combined Vercel deployments now use the correct /api server URL for browser and preview environments.
    • Generated environment files consistently configure API and server URLs for Vercel deployments.
    • Preserved localhost defaults for non-Vercel deployment configurations.

@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown

@kzndotsh is attempting to deploy a commit to the Better T Stack Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 42862713-816c-4ca7-800e-647ea3421d75

📥 Commits

Reviewing files that changed from the base of the PR and between bce8104 and 29f76e4.

📒 Files selected for processing (4)
  • apps/cli/test/deployment.test.ts
  • packages/template-generator/src/core/template-processor.ts
  • packages/template-generator/src/processors/env-vars.ts
  • packages/template-generator/src/processors/varlock.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The template generator now defaults missing server URLs to /api. Combined Vercel deployments generate relative client and server URL values. Deployment tests validate browser-origin and preview deployment RPC URL resolution.

Changes

Vercel server URL handling

Layer / File(s) Summary
Default server URL resolution
packages/template-generator/src/core/template-processor.ts
getServerUrl accepts `string
Deployment environment values
packages/template-generator/src/processors/env-vars.ts, packages/template-generator/src/processors/varlock.ts
Client environment generation and empty SERVER_URL values use /api when both deployments target Vercel. Other deployment combinations retain the localhost value.
Combined Vercel deployment tests
apps/cli/test/deployment.test.ts
Tests update generated client expectations and validate /api values plus browser-origin and preview deployment RPC URLs.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 4c526

The generated Vercel client URLs resolve to the deployment origin with a single /api prefix, so no actionable merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: setting /api client URLs for combined Vercel deployments.
Linked Issues check ✅ Passed Issue #1237 requires a valid generated client server URL and protection from the initialization-time endsWith TypeError. env-vars.ts now generates /api when both deployment targets are Vercel. `…
Out of Scope Changes check ✅ Passed The changes stay within issue #1237. The template, environment generation, schema generation, and deployment tests directly support valid Vercel client configuration and safe URL resolution. No unrela…
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Combined Vercel stacks crashed in getServerUrl when ENV.VITE_SERVER_URL was missing, and .env still seeded localhost instead of the same-origin /api path.

Fixes AmanVarshney01#1237
@kzndotsh
kzndotsh force-pushed the fix/vercel-client-server-url-1237 branch from 29f76e4 to 4c526bb Compare September 15, 2026 22:03
Wundero added a commit to Wundero/create-better-t-stack that referenced this pull request Oct 8, 2026
# Conflicts:
#	apps/cli/test/deployment.test.ts
#	packages/template-generator/src/core/template-processor.ts
#	packages/template-generator/src/processors/env-vars.ts
Wundero added a commit to Wundero/create-better-t-stack that referenced this pull request Oct 8, 2026
Port AmanVarshney01#1177's Nitro branch into the relocated api/orpc|trpc context templates, point the Nitro CORS middleware at main's varlock env, await the async Cloudflare auth handler, cast Nitro's event.req to Request for the Cloudflare preset, and drop composite from the Nitro tsconfig so Prisma's inferred client type is emittable. Adapt the AmanVarshney01#1177/AmanVarshney01#1242 tests to main's relocated files and harness conventions.

This branch has not been deployed

No deployments
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.

Error encountered after the new project was initialized.

1 participant