Skip to content

Commit 3433803

Browse files
authored
fix(docs): collapse the metadataBase hostname into SITE_URL, record the middleware decision (#204)
metadataBase in app/layout.tsx now derives from SITE_URL instead of repeating the canonical host. middleware.ts keeps its own literal by measurement, not by assumption: importing @/lib/seo from middleware grows the edge runtime bundle from 149,491 B to 14,849,913 B while next build still exits 0, so no gate would ever report it. Both sides now state the reason for the duplication rather than instructing a human to keep them in sync. Rendered metadata verified unchanged: 12,347 URL-bearing head-tag rows across 577 prerendered pages, 0 differing lines. Closes #199
1 parent 01b29d9 commit 3433803

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

‎apps/docs/app/layout.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import './global.css';
22
import type { ReactNode } from 'react';
33
import type { Metadata } from 'next';
4+
import { SITE_URL } from '@/lib/seo';
45

56
export const metadata: Metadata = {
6-
metadataBase: new URL('https://docs.objectos.ai'),
7+
metadataBase: new URL(SITE_URL),
78
title: {
89
template: '%s | ObjectOS',
910
default: 'ObjectOS',

‎apps/docs/lib/seo.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,23 @@
11
import { i18n } from '@/lib/i18n';
22
import { source } from '@/lib/source';
33

4-
// Canonical production host. Keep in sync with middleware's domain redirect.
4+
/**
5+
* Canonical production host — the origin every absolute URL in this module is
6+
* built on, and the `metadataBase` every relative metadata URL resolves against.
7+
*
8+
* `middleware.ts` spells the same host out a second time, and that duplication
9+
* is a decision rather than an oversight. It cannot import this constant: this
10+
* module imports `lib/source.ts`, so the import would drag the fumadocs loader
11+
* and every compiled MDX module into the edge runtime the middleware runs in.
12+
* Measured on this tree — middleware importing `SITE_URL` from here takes the
13+
* edge bundle from 149 KB to 14.7 MB of JavaScript, with `next build` still
14+
* exiting 0, so the cost surfaces at deploy rather than in CI.
15+
*
16+
* The reason is recorded on both sides instead of a sync instruction, because
17+
* an instruction to a human is not a mechanism. Nothing here enforces that the
18+
* two agree; collapsing them properly needs a leaf module both runtimes can
19+
* import, which is a change to the file layout rather than to either file.
20+
*/
521
export const SITE_URL = 'https://docs.objectos.ai';
622

723
/**

‎apps/docs/middleware.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ import { i18n } from '@/lib/i18n';
44

55
const LOCALE_COOKIE = 'FD_LOCALE';
66

7+
/**
8+
* The canonical docs host, and the legacy host that redirects to it.
9+
*
10+
* `CANONICAL_HOST` holds the same value as `SITE_URL` in `lib/seo.ts`, written
11+
* out a second time on purpose. This file runs in the **edge runtime**, and
12+
* `lib/seo.ts` imports `lib/source.ts` — so importing the constant from there
13+
* would pull the fumadocs loader and all 413 compiled MDX modules into this
14+
* bundle. Measured on this tree: the edge bundle goes from 149 KB to 14.7 MB of
15+
* JavaScript, and `next build` still exits 0, so nothing in CI would say so.
16+
*
17+
* Two copies of one hostname is the smaller cost, and the copy belongs on this
18+
* side: this redirect answers "which host is canonical" for every request
19+
* before any page code runs, and that answer should not depend on the module
20+
* graph that builds pages. Collapsing the two would take a leaf module both
21+
* runtimes can import — not an import from `lib/seo.ts`.
22+
*
23+
* Nothing enforces that the two agree. That is the residual cost of the
24+
* decision, stated here so it is visible rather than discovered.
25+
*/
26+
const CANONICAL_HOST = 'docs.objectos.ai';
27+
const LEGACY_HOST = 'www.objectos.app';
28+
729
/**
830
* Supported languages extracted from i18n configuration
931
*/
@@ -101,12 +123,12 @@ function getPreferredLanguage(request: NextRequest): string {
101123
* - Stores language preference as a cookie
102124
*/
103125
export default function middleware(request: NextRequest) {
104-
// Canonical domain redirect: legacy docs host -> docs.objectos.ai (permanent).
126+
// Canonical domain redirect: legacy docs host -> canonical host (permanent).
105127
const host = request.headers.get('host');
106-
if (host === 'www.objectos.app') {
128+
if (host === LEGACY_HOST) {
107129
const target = new URL(request.url);
108130
target.protocol = 'https:';
109-
target.host = 'docs.objectos.ai';
131+
target.host = CANONICAL_HOST;
110132
target.port = '';
111133
return NextResponse.redirect(target, 308);
112134
}

0 commit comments

Comments
 (0)