F146: URL-based site routing (proxy-rewrite core)#1
Merged
Conversation
Active site can now live in the URL: /admin/{slug}/... resolves the site,
injects cms-active-* cookies on the forwarded request, and rewrites back to
/admin/... so the existing route tree renders unchanged. Browser keeps the
pretty slug URL. Solves the parallel-tab cookie tug-of-war: two tabs on
different /admin/{slug} URLs render their own site regardless of the shared
cookie.
Approach: proxy-rewrite, NOT a 25-folder move — far lower risk, no link
codemod required up front (cookie fallback keeps existing /admin/... links
working). New lib/site-slug-routing.ts owns the reserved-segment set + slug
parsing + siteAdminPath() helper for incremental link migration.
Critical fix found via browser verification: must STRIP existing cms-active-*
from the cookie header before injecting, else a duplicate same-named cookie
shadows the URL slug (parser keeps the first/stale one) and the URL loses to
the cookie. Applied to both the slug path and the ?site= API path.
Verified against :3010 (HTTPS): /admin/trail/settings → <title>Trail</title>,
/admin/sanneandersen/settings → Sanne Andersen, and URL wins over a
conflicting cookie in all 3 cross-site cases; no-slug still falls back to
cookie. 13 unit tests for parse/build/round-trip. Unknown slug falls through
to legacy collection redirect (307); reserved segments unaffected.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
switchSite() now hard-navigates to siteAdminPath(destination, siteId) so a
switch lands on the slug URL (/admin/{slug}) instead of bare /admin. The
cookie is still set as fallback for cookie-only callers. Combined with the
proxy rewrite, switching to a site now produces a stable, bookmarkable,
tab-independent URL.
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.
F146 — URL-Based Site Routing
Active site can now live in the URL: `/admin/{slug}/...`. Solves the daily parallel-tab cookie tug-of-war, makes bookmarks stable, and makes shared admin links land on the right site.
Approach: proxy-rewrite (NOT a 25-folder move)
`proxy.ts` detects `/admin/{slug}/...` where `{slug}` is a known registry site, injects `cms-active-*` cookies on the forwarded request, and `NextResponse.rewrite()`s back to `/admin/...` so the existing route tree renders unchanged. Browser keeps the pretty slug URL. Far lower risk than physically moving 25 route folders + a 22-file link codemod — those links keep working via the cookie fallback and can migrate incrementally via the new `siteAdminPath()` helper.
What's in this PR
Verified against :3010 (HTTPS)
Deferred (follow-up, documented in plan-doc)
🤖 Generated with Claude Code