The serving contract enumerated every public path the bundled fixture happened to contain, and the generated nginx published exactly those as `location =` blocks. A record published after the build — the entire point of having a backend — answered 404 at the edge before the SPA was ever asked, and no amount of correct routing inside the bundle could recover it. Twenty-seven frozen paths, and any twenty-eighth was unreachable. The route contract already declares which paths exist; the catalog only decides which of them currently resolve, and that is the SPA's call rather than the web server's. So the contract now emits one regex per registered Public route, derived from the router, the way the Studio half has always worked. A parameter matches one segment and never a slash, so /cases/a/b stays a 404 instead of quietly rendering a case page. The catch-all route is dropped rather than translated: serving index.html for every unmatched URL would turn an edge 404 into a soft 200 and hide broken links from crawlers and from us. Verified against a built image: /cases/a-brand-new-slug now answers 200 while /nope and /cases/a/b still answer 404. schemaVersion goes to 2 because the field changed shape, not just contents — a consumer reading publicSpaPaths would otherwise see an absent key rather than a version it can refuse.
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { pathToFileURL } from "node:url";
|
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
import { tmpdir } from "node:os";
|
|
import path from "node:path";
|
|
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
|
|
import { writeTechLogServingArtifact } from "../../scripts/lib/tech-log-serving-artifact.ts";
|
|
|
|
const roots: string[] = [];
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(roots.splice(0).map((root) => rm(root, { recursive: true })));
|
|
});
|
|
|
|
describe("TechLog serving artifact", () => {
|
|
it("emits a self-contained deployment server and its route contract", async () => {
|
|
const root = await mkdtemp(path.join(tmpdir(), "tech-log-serving-artifact-"));
|
|
roots.push(root);
|
|
const contract = {
|
|
schemaVersion: 2 as const,
|
|
publicSpaPathPatterns: ["^/$", "^/projects/[^/]+$"],
|
|
studioPathPrefix: "/studio" as const,
|
|
studioSpaPathPatterns: ["^/studio$"],
|
|
notFound: {
|
|
status: 404 as const,
|
|
contentType: "text/plain;charset=UTF-8" as const,
|
|
body: "Not Found" as const,
|
|
},
|
|
};
|
|
|
|
await writeTechLogServingArtifact({ distRoot: root, contract });
|
|
|
|
expect(
|
|
JSON.parse(
|
|
await readFile(path.join(root, "tech-log-serving-contract.json"), "utf8"),
|
|
),
|
|
).toEqual(contract);
|
|
const serverModule = await import(
|
|
`${pathToFileURL(path.join(root, "server.mjs")).href}?test=${Date.now()}`
|
|
);
|
|
expect(serverModule.createTechLogProductionServer).toEqual(expect.any(Function));
|
|
});
|
|
});
|