Skip to content
Myr

Serve the web's www host as a redirect to its bare host

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Prod's web Worker takes www.<domain> as a second Custom Domain, and the web answers any www. host with a 301 to the bare host (a 308 for a write), path and query kept.

authored by oscabriel · committed by oscabriel · parent 1ece295 · Browse files · 6 files+60 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+60 added−8 removed

  • tests:+29 added−1 removed
  • other:+31 added−7 removed

6 files+60 added−8 removed

modified:apps/web/src/server/addresses.ts+21 added-2 removed
modified:apps/web/test/legacy-redirect.test.ts+28 added
78 unmodified lines
79 expect(edge.headers.get("cache-control")).toContain("public");80 });81});8283const onWww = (path: string, method = "GET") =>84 Option.map(85 canonicalAddress(86 new Request(`https://www.web-test.example${path}`, { method })87 ),88 (response) => [response.status, response.headers.get("location")]89 );9091describe("an address on a www. host", () => {92 it("is a 301 to the bare host, the path and the query kept", () => {93 expect(onWww("/")).toStrictEqual(94 Option.some([301, "https://web-test.example/"])95 );96 expect(onWww("/oscabriel/datekit/tree/main?x=1")).toStrictEqual(97 Option.some([98 301,99 "https://web-test.example/oscabriel/datekit/tree/main?x=1",100 ])101 );102 });103104 it("is a 308 for a request that is not a read, so it keeps its method", () => {105 expect(onWww("/oscabriel/datekit", "POST")).toStrictEqual(106 Option.some([308, "https://web-test.example/oscabriel/datekit"])107 );108 });109});110111describe("an address that needs no redirect", () => {112 it("goes on to the pages: a canonical name, a source path, and a word no project has", () => {113 expect(movedTo("/oscabriel/datekit/tree/main")).toStrictEqual(114 Option.none()
31 unmodified lines
modified:apps/web/wrangler.jsonc+1 added-1 removed
51 unmodified lines
52 "PUBLIC_PLATFORM_URL": "https://platform-demo.oscargabriel.workers.dev",53 },54 },55 // Served on the brand's own domain, never workers.dev: infra/deploy.ts56 // passes its Custom Domain and PUBLIC_PLATFORM_URL, which name the brand,56 // passes its Custom Domains and PUBLIC_PLATFORM_URL, which name the brand,57 // so they live in infra/stages.ts. The URL here is a stand-in the58 // deploy's --var replaces, so the generated Env still types it a string.59 "prod": {60 "workers_dev": false,
8 unmodified lines
modified:infra/deploy.ts+2 added-3 removed
65 unmodified lines
66// name them here, never from `wrangler.jsonc` (see `customHosts`).67const hostArgs = (stage: Stage) =>68 Option.match(customHosts(stage), {69 onNone: () => ({ platform: [], web: [] }),70 onSome: ({ platform, web }) => ({70 onSome: ({ platform, web, webAliases }) => ({71 platform: [72 "--domain",73 platform,74 "--var",75 `PUBLIC_WEB_URL:https://${web}`,76 ],77 web: [78 "--domain",79 web,78 ...[web, ...webAliases].flatMap((host) => ["--domain", host]),79 "--var",80 `PUBLIC_PLATFORM_URL:https://${platform}`,81 ],82 }),
211 unmodified lines
modified:infra/stages.ts+7 added-1 removed
30 unmodified lines
3132export interface Hosts {33 readonly platform: string;34 readonly web: string;35 // More Custom Domains on the web's Worker, each answered with a 301 to `web`.36 readonly webAliases: readonly string[];37}3839// A stage served on the brand's own domain, as Workers Custom Domains. The40// names live here, not in `wrangler.jsonc`, so the brand stays in
4 unmodified lines
45export const URL_FROM_DEPLOY = "https://from-infra-deploy.invalid";4647export const customHosts = (stage: Stage): Option.Option<Hosts> =>48 stage === "prod"47 ? Option.some({ platform: `git.${Brand.domain}`, web: Brand.domain })49 ? Option.some({50 platform: `git.${Brand.domain}`,51 web: Brand.domain,52 webAliases: [`www.${Brand.domain}`],53 })54 : Option.none();5556export interface Resources {57 readonly platform: string;
114 unmodified lines
modified:packages/config/test/deploy.test.ts+1 added-1 removed
462 unmodified lines
463 ".$ bun run verify",464 "apps/sandbox$ wrangler deploy --env prod",465 `apps/platform$ varlock-wrangler deploy --env prod --domain ${git} --var PUBLIC_WEB_URL:https://${Brand.domain}`,466 "apps/web$ bun run build",467 `apps/web$ wrangler deploy --env prod --domain ${Brand.domain} --var PUBLIC_PLATFORM_URL:https://${git}`,467 `apps/web$ wrangler deploy --env prod --domain ${Brand.domain} --domain www.${Brand.domain} --var PUBLIC_PLATFORM_URL:https://${git}`,468 ".$ bun run bootstrap --stage prod --check-triggers",469 ".$ bun scripts/smoke.ts --stage prod",470 ]);471 })
24 unmodified lines