Skip to content

fix: use VERCEL_URL for preview baseUrl to prevent CORS errors#360

Merged
brendanjryan merged 1 commit into
mainfrom
fix/vercel-preview-cors
Mar 18, 2026
Merged

fix: use VERCEL_URL for preview baseUrl to prevent CORS errors#360
brendanjryan merged 1 commit into
mainfrom
fix/vercel-preview-cors

Conversation

@brendanjryan

Copy link
Copy Markdown
Collaborator

Problem

Preview deployments show "Failed to load services — Failed to fetch" on the /services page. All relative fetches (/api/services, RSC requests) fail with CORS errors.

Root Cause

Vocs injects a <base href="..."> tag using the configured baseUrl. For preview builds, this was set to VERCEL_BRANCH_URL (e.g. mpp-git-branchname-tempoxyz.vercel.app). When visiting via the deployment-specific URL (mpp-{hash}-tempoxyz.vercel.app), all relative fetches resolve against the wrong origin → CORS blocks them.

This was previously masked by Vercel Deployment Protection (password auth), which canonicalized all traffic through the branch URL. After removing password auth, the origin mismatch is exposed.

Fix

Remove the VERCEL_BRANCH_URL preference and use VERCEL_URL (the deployment-specific URL) instead. VERCEL_URL always matches the URL being visited, so the <base> tag resolves correctly.

@vercel

vercel Bot commented Mar 18, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mpp Ready Ready Preview, Comment Mar 18, 2026 3:27am

Request Review

VERCEL_BRANCH_URL was used as the baseUrl for preview deployments, which
Vocs injects as a <base href> tag. When visiting via the deployment-specific
URL (e.g. mpp-{hash}-tempoxyz.vercel.app), all relative fetches resolved
against the branch URL instead — causing CORS failures on /api/services
and RSC requests.

This was previously masked by Vercel Deployment Protection (password auth)
which canonicalized traffic to the branch URL. After removing password auth,
the mismatch is exposed.

Fix: prefer VERCEL_URL (matches the visited URL) over VERCEL_BRANCH_URL.
@brendanjryan brendanjryan force-pushed the fix/vercel-preview-cors branch from dc66423 to 901f8d3 Compare March 18, 2026 03:25
@brendanjryan brendanjryan merged commit 7e94fd0 into main Mar 18, 2026
8 checks passed
@brendanjryan brendanjryan deleted the fix/vercel-preview-cors branch March 18, 2026 03:29

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 901f8d3e6f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vocs.config.ts
return `https://${process.env.VERCEL_PROJECT_PRODUCTION_URL}`;
if (process.env.VERCEL_BRANCH_URL)
return `https://${process.env.VERCEL_BRANCH_URL}`;
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid pinning preview baseUrl to the commit-specific URL

When VERCEL_ENV !== "production", Vercel previews are reachable through both a branch URL and a commit-specific URL. This line now always sets Vocs' baseUrl from VERCEL_URL, and Vocs uses baseUrl to emit a <base> tag, so anyone opening the branch URL gets a page whose relative requests are rewritten to the commit host instead of the current origin. That means client fetches like fetch("/api/services") in src/data/registry.ts:8 can still fail with the same cross-origin/auth issues on the branch preview—the change only flips which preview hostname works.

Useful? React with 👍 / 👎.

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.

1 participant