fix: product subdomain cleanup

This commit is contained in:
2026-07-23 20:52:49 -04:00
parent a6ef4d2955
commit 8e33af43a5
39 changed files with 1597 additions and 630 deletions

View File

@@ -8,6 +8,8 @@
import { describe, it, expect } from "bun:test";
import {
resolveSiteFromHost,
resolveSiteFromPath,
resolveSiteFromLocation,
SITE_CONFIG,
type SiteId
} from "./site-context";
@@ -80,15 +82,12 @@ describe("resolveSiteFromHost", () => {
});
it("every SITE_CONFIG entry has a non-empty baseRoutePrefix for subdomains", () => {
for (const id of [
"nessa",
"lineage",
"gaze",
"inputhalo"
] as SiteId[]) {
for (const id of ["nessa", "lineage", "gaze", "inputhalo"] as SiteId[]) {
expect(SITE_CONFIG[id].baseRoutePrefix).toBe(`/${id}`);
expect(SITE_CONFIG[id].subdomain).toBe(id);
expect(SITE_CONFIG[id].titleSuffix).toBe(` | ${SITE_CONFIG[id].displayName}`);
expect(SITE_CONFIG[id].titleSuffix).toBe(
` | ${SITE_CONFIG[id].displayName}`
);
}
});
@@ -97,3 +96,67 @@ describe("resolveSiteFromHost", () => {
expect(SITE_CONFIG.main.baseRoutePrefix).toBe("");
});
});
describe("resolveSiteFromPath", () => {
it("maps a subdomain-prefixed path to the right site", () => {
expect(resolveSiteFromPath("/nessa/contact")?.id).toBe("nessa");
expect(resolveSiteFromPath("/lineage/downloads")?.id).toBe("lineage");
expect(resolveSiteFromPath("/gaze/")?.id).toBe("gaze");
expect(resolveSiteFromPath("/inputhalo/privacy")?.id).toBe("inputhalo");
});
it("matches the exact prefix (landing page)", () => {
expect(resolveSiteFromPath("/nessa")?.id).toBe("nessa");
expect(resolveSiteFromPath("/gaze")?.id).toBe("gaze");
});
it("returns null for non-subdomain paths", () => {
expect(resolveSiteFromPath("/")).toBeNull();
expect(resolveSiteFromPath("/contact")).toBeNull();
expect(resolveSiteFromPath("/blog/post")).toBeNull();
expect(resolveSiteFromPath("/downloads")).toBeNull();
});
it("does not match prefix substrings (no false positives)", () => {
// `/nessa-extra` must NOT match `/nessa`.
expect(resolveSiteFromPath("/nessa-extra")).toBeNull();
expect(resolveSiteFromPath("/gazette")).toBeNull();
});
it("handles empty / null / undefined", () => {
expect(resolveSiteFromPath("")).toBeNull();
expect(resolveSiteFromPath(null)).toBeNull();
expect(resolveSiteFromPath(undefined)).toBeNull();
});
it("returns the full SITE_CONFIG entry", () => {
expect(resolveSiteFromPath("/nessa/contact")).toEqual(SITE_CONFIG.nessa);
expect(resolveSiteFromPath("/gaze")).toEqual(SITE_CONFIG.gaze);
});
});
describe("resolveSiteFromLocation", () => {
it("prefers the host when it identifies a subdomain", () => {
expect(resolveSiteFromLocation("nessa.freno.me", "/contact").id).toBe(
"nessa"
);
expect(resolveSiteFromLocation("gaze.localhost", "/").id).toBe("gaze");
});
it("falls back to the path prefix when the host is localhost/main", () => {
expect(resolveSiteFromLocation("localhost", "/nessa/contact").id).toBe(
"nessa"
);
expect(resolveSiteFromLocation("localhost", "/lineage/").id).toBe(
"lineage"
);
expect(resolveSiteFromLocation("freno.me", "/gaze/downloads").id).toBe(
"gaze"
);
});
it("returns main when neither host nor path identifies a subdomain", () => {
expect(resolveSiteFromLocation("localhost", "/contact").id).toBe("main");
expect(resolveSiteFromLocation("freno.me", "/").id).toBe("main");
});
});