Skip to content

Commit 09a0dd9

Browse files
authored
fix(docs): compare hostname, not authority, in legacy-host redirect (#228)
The Host header carries host[:port], so comparing it whole against a bare hostname meant www.objectos.app:8080 was never equal to LEGACY_HOST. It fell through to locale negotiation and was served under the legacy host (200) instead of redirected off it (308). Three lines below, the same block already stripped the port from the target, so the port was accounted for on the way out and not on the way in. Compares the hostname now. The target-side normalisation is unchanged. Verified with the redirect table established by #204, #223, #225 and #227, plus two rows: the ported legacy host now 308s with no port on the target, and Host: docs.objectos.ai:3000 stays 200 on both sides -- which proves the comparison is against LEGACY_HOST specifically rather than a blanket port strip, a fix that would have passed every other row. The before column was reproduced by rebuilding and running the pre-fix file, not inferred. Closes #226
1 parent f78a077 commit 09a0dd9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎apps/docs/middleware.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,18 @@ function getPreferredLanguage(request: NextRequest): string {
253253
*/
254254
export default function middleware(request: NextRequest) {
255255
// Canonical domain redirect: legacy docs host -> canonical host (permanent).
256+
//
257+
// The Host header carries the authority, `host[:port]` (RFC 9110 §7.2), not
258+
// just the hostname. Comparing it whole tested only the bare-host shape:
259+
// `www.objectos.app:8080` is not `=== LEGACY_HOST`, so a ported request fell
260+
// through to locale negotiation and got served (200) under the legacy host
261+
// instead of redirected (308) off it — while three lines below, the target
262+
// side already strips its port (`target.port = ''`). The port was accounted
263+
// for on the way out and not on the way in (#226); comparing the hostname on
264+
// both sides closes that gap without changing the target normalisation.
256265
const host = request.headers.get('host');
257-
if (host === LEGACY_HOST) {
266+
const hostname = host?.split(':')[0];
267+
if (hostname === LEGACY_HOST) {
258268
const target = new URL(request.url);
259269
target.protocol = 'https:';
260270
target.host = SITE_HOST;

0 commit comments

Comments
 (0)