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:
@@ -7,9 +7,13 @@ const publicRoutePaths = Object.values(TECH_LOG_ROUTE_REGISTRY)
|
||||
.filter((route) => route.layoutGroup === "PUBLIC")
|
||||
.map((route) => route.path);
|
||||
|
||||
const studioRoutePaths = Object.values(TECH_LOG_ROUTE_REGISTRY)
|
||||
.filter((route) => route.layoutGroup === "STUDIO")
|
||||
.map((route) => route.path);
|
||||
|
||||
describe("TechLog production serving contract", () => {
|
||||
it("derives one pattern per registered Public route", () => {
|
||||
const contract = createTechLogServingContract({ publicRoutePaths });
|
||||
const contract = createTechLogServingContract({ publicRoutePaths, studioRoutePaths });
|
||||
|
||||
expect(contract.schemaVersion).toBe(2);
|
||||
expect(contract.publicSpaPathPatterns).toEqual([
|
||||
@@ -31,15 +35,23 @@ describe("TechLog production serving contract", () => {
|
||||
"^/topics/[^/]+$",
|
||||
]);
|
||||
expect(contract.studioPathPrefix).toBe("/studio");
|
||||
// Derived from the route contract and sorted, exactly like the public half.
|
||||
// The old hand-written array folded the four document sub-screens into one
|
||||
// alternation; deriving them yields one pattern per route, which is the
|
||||
// point — a route that exists is served, without anyone remembering to add it.
|
||||
expect(contract.studioSpaPathPatterns).toEqual([
|
||||
"^/studio$",
|
||||
"^/studio/assets$",
|
||||
"^/studio/taxonomy$",
|
||||
"^/studio/documents$",
|
||||
"^/studio/documents/[^/]+/edit$",
|
||||
"^/studio/documents/[^/]+/preview$",
|
||||
"^/studio/documents/[^/]+/publish$",
|
||||
"^/studio/documents/[^/]+/validation$",
|
||||
"^/studio/documents/new$",
|
||||
"^/studio/documents/[^/]+/(edit|validation|preview|publish)$",
|
||||
"^/studio/publications$",
|
||||
"^/studio/publications/[^/]+/preview$",
|
||||
"^/studio/releases$",
|
||||
"^/studio/taxonomy$",
|
||||
]);
|
||||
expect(contract.notFound).toEqual({
|
||||
status: 404,
|
||||
@@ -54,7 +66,7 @@ describe("TechLog production serving contract", () => {
|
||||
* record must be served whatever its slug.
|
||||
*/
|
||||
it("serves a slug the build never saw", () => {
|
||||
const { publicSpaPathPatterns } = createTechLogServingContract({ publicRoutePaths });
|
||||
const { publicSpaPathPatterns } = createTechLogServingContract({ publicRoutePaths, studioRoutePaths });
|
||||
const matches = (pathname: string) =>
|
||||
publicSpaPathPatterns.some((pattern) => new RegExp(pattern).test(pathname));
|
||||
|
||||
@@ -65,7 +77,7 @@ describe("TechLog production serving contract", () => {
|
||||
|
||||
/** A parameter is one segment. Extra depth is a 404, not a soft 200. */
|
||||
it("does not let a parameter swallow a slash", () => {
|
||||
const { publicSpaPathPatterns } = createTechLogServingContract({ publicRoutePaths });
|
||||
const { publicSpaPathPatterns } = createTechLogServingContract({ publicRoutePaths, studioRoutePaths });
|
||||
const matches = (pathname: string) =>
|
||||
publicSpaPathPatterns.some((pattern) => new RegExp(pattern).test(pathname));
|
||||
|
||||
@@ -81,6 +93,7 @@ describe("TechLog production serving contract", () => {
|
||||
it("drops the catch-all route", () => {
|
||||
const { publicSpaPathPatterns } = createTechLogServingContract({
|
||||
publicRoutePaths: ["/", "*"],
|
||||
studioRoutePaths,
|
||||
});
|
||||
expect(publicSpaPathPatterns).toEqual(["^/$"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user