fix(client): route gateway same-origin for any deployment subdomain (renamed-app 404) - #14
Merged
Merged
Conversation
The gateway base was chosen by comparing the live host to the
build-time-baked VITE_BOOL_SLUG (location.host === `${slug}.${appHost}`).
Vite inlines VITE_* at build time, so when a project's slug/domain is
changed after the bundle is built, the baked slug goes stale: the app is
served at `<new-slug>.<appHost>`, the exact match fails, and the client
falls through to an absolute `${appOrigin}/served/<old-slug>` gateway URL.
That slug no longer exists, so every gateway call 404s — most visibly the
"Continue with Google" navigation, which opens a tab straight onto the
404.
The platform proxy resolves the gateway slug from the REQUEST host, not
the baked slug, so any `<label>.<appHost>` deployment subdomain is
reachable same-origin. Detect that shape (new isDeploymentSubdomain,
mirroring the proxy's deploymentSlugFromHost) instead of matching the
baked slug. Renamed apps now stay same-origin and keep working with no
rebuild. Preview sandboxes and custom domains are unchanged (still the
cross-origin baked-origin path).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
A generated app served at
funky-ninja.bool.sohas its slug/domain changed after it was built. Clicking Continue with Google opens a tab that 404s. (Same root cause silently 404s the app's data/gateway calls too — Google is just the one that navigates a visible tab.)Root cause
boolGatewayBase()picked the same-origin (relative) path only when the live host exactly equaled the build-time-baked slug's subdomain:Vite inlines every
VITE_*at build time, soVITE_BOOL_SLUGis frozen into the bundle. Renaming the project (app/api/projects/[id]/route.tsPATCHslug) does not rebuild — so the live app at<new-slug>.bool.sostill carries the old baked slug. The exact match fails, the client falls through to the absolute branch`${appOrigin}/served/<old-slug>`, and the gateway (handleGatewayUsers, which resolves the tenant by slug) 404s because the old slug is gone.Fix
The platform proxy (
proxy.ts→deploymentSlugFromHost) resolves the gateway slug from the request host, not the baked slug — so any<label>.<appHost>deployment subdomain is reachable same-origin. Match on that subdomain shape instead of the baked slug (isDeploymentSubdomain, mirroring the proxy). Renamed apps stay same-origin and just work, with no rebuild.*.vercel.run) and custom domains are unchanged — they still use the cross-origin baked-origin path.isDeploymentSubdomainis exported fromclient.tsfor tests but not re-exported fromindex.ts.Tests
bun test— 106 pass. Adds a renamed-app regression (live subdomain ≠ baked slug → still relative) and direct unit coverage ofisDeploymentSubdomain(port stripping, apex, multi-label, foreign domains, empty inputs).Release note
This reaches already-deployed apps only on their next publish build (the SDK is bundled at build time). Needs a canary/
nextpublish to roll out; stable^0.1.xapps pick it up on their next build per the caret range.🤖 Generated with Claude Code