fix: derive the Studio serving patterns from the route contract

`/studio/releases` answered a plain-text 404 from nginx. The route existed, the
chunk was built, and the SPA could reach the screen by client-side navigation —
but a hard load or a reload never got that far, because the web server had
never been told the path exists.

The public half of the serving contract derives its patterns from the route
registry. The Studio half was a hand-maintained array, and it failed the way
hand-maintained arrays fail: the comment above `^/studio/assets$` records that
exact bug being fixed once already, and adding a route repeated it immediately.
Both halves now come from the same source, so a Studio route that exists is
served without anyone having to remember.

Deriving them yields one pattern per route rather than the old alternation that
folded the four document sub-screens together. Same matched set, and it no
longer needs a human to keep the grouping honest.
This commit is contained in:
DongHyeonka
2026-08-21 03:29:47 +09:00
parent 3754269118
commit ab8c6c14db
3 changed files with 47 additions and 29 deletions
+24 -23
View File
@@ -31,6 +31,8 @@ type ServingContractInput = Readonly<{
* pure transform the tests can drive directly.
*/
publicRoutePaths: readonly string[];
/** The Studio route templates, same form and same reason. */
studioRoutePaths: readonly string[];
}>;
/**
@@ -49,42 +51,41 @@ function patternOf(routePath: string): string {
return `^${escaped === "" ? "/" : escaped}$`;
}
const studioSpaPathPatterns = Object.freeze([
"^/studio$",
// The Asset Library is a first-class Studio route (TECH_LOG_STUDIO_ASSETS in
// the route contract) but was never listed here, so a hard navigation or a
// reload of /studio/assets was served the in-shell Studio 404 -- the screen
// was only reachable by client-side navigation from another Studio page.
"^/studio/assets$",
"^/studio/taxonomy$",
"^/studio/documents$",
"^/studio/documents/new$",
"^/studio/documents/[^/]+/(edit|validation|preview|publish)$",
"^/studio/publications$",
"^/studio/publications/[^/]+/preview$",
]);
function asciiCompare(left: string, right: string): number {
return left < right ? -1 : left > right ? 1 : 0;
}
export function createTechLogServingContract({
publicRoutePaths,
}: ServingContractInput): TechLogServingContract {
/**
* The catch-all is the SPA's own not-found screen; serving index.html for every
* unmatched URL would turn the edge 404 into a soft 200 and hide broken links
* from crawlers and from us.
*/
function patternsFor(routePaths: readonly string[]): readonly string[] {
const patterns = new Set<string>();
for (const routePath of publicRoutePaths) {
// The catch-all is the SPA's own not-found screen; serving index.html for
// every unmatched URL would turn the edge 404 into a soft 200 and hide
// broken links from crawlers and from us.
for (const routePath of routePaths) {
if (routePath === "*" || routePath.includes("*")) continue;
patterns.add(patternOf(routePath));
}
return Object.freeze([...patterns].sort(asciiCompare));
}
export function createTechLogServingContract({
publicRoutePaths,
studioRoutePaths,
}: ServingContractInput): TechLogServingContract {
return Object.freeze({
schemaVersion: 2,
publicSpaPathPatterns: Object.freeze([...patterns].sort(asciiCompare)),
publicSpaPathPatterns: patternsFor(publicRoutePaths),
studioPathPrefix: "/studio",
studioSpaPathPatterns,
// Derived, not listed. This was a hand-maintained array, and it went stale
// exactly the way a hand-maintained array does: /studio/assets was missing
// for its whole life, and /studio/releases repeated the mistake the moment
// it was added — the route worked by client-side navigation and 404'd on
// reload, because nginx had never heard of it. The route contract already
// knows which Studio paths exist, so ask it.
studioSpaPathPatterns: patternsFor(studioRoutePaths),
notFound: Object.freeze({
status: 404,
contentType: "text/plain;charset=UTF-8",