Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions __tests__/canonical.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ import {

describe("canonicalUrl", () => {
it("returns the absolute URL for the root path", () => {
expect(canonicalUrl("/")).toBe("https://docs.openprose.ai/");
expect(canonicalUrl("/")).toBe("https://docs.prose.md/");
});

it("returns the absolute URL for a nested path", () => {
expect(canonicalUrl("/get-started/install")).toBe(
"https://docs.openprose.ai/get-started/install",
"https://docs.prose.md/get-started/install",
);
});

it("ignores the runtime hostname (always pins to docs.openprose.ai)", () => {
it("ignores the runtime hostname (always pins to docs.prose.md)", () => {
// Regression: even when running on openprose-docs.fly.dev during preview,
// canonical must point to docs.openprose.ai per spec Section 6.
expect(canonicalUrl("/foo")).toContain("docs.openprose.ai");
// canonical must point to docs.prose.md per spec Section 6.
expect(canonicalUrl("/foo")).toContain("docs.prose.md");
expect(canonicalUrl("/foo")).not.toContain("fly.dev");
});
});
Expand All @@ -40,7 +40,7 @@ describe("buildPageMetadata", () => {
it("emits absolute canonical URL for a nested docs path", () => {
const md = buildPageMetadata("/docs/get-started/install");
expect(md.alternates?.canonical).toBe(
"https://docs.openprose.ai/docs/get-started/install",
"https://docs.prose.md/docs/get-started/install",
);
});

Expand Down
20 changes: 20 additions & 0 deletions __tests__/proxy.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { describe, expect, it } from 'vitest';
import { resolveDocsHostRedirect } from '../proxy';

describe('resolveDocsHostRedirect', () => {
it('redirects the legacy docs host to docs.prose.md', () => {
expect(resolveDocsHostRedirect('docs.openprose.ai', '/foo?x=1')).toBe(
'https://docs.prose.md/foo?x=1',
);
});

it('ignores the canonical docs host', () => {
expect(resolveDocsHostRedirect('docs.prose.md', '/foo?x=1')).toBeNull();
});

it('ignores the Fly preview host', () => {
expect(
resolveDocsHostRedirect('openprose-docs.fly.dev', '/foo?x=1'),
).toBeNull();
});
});
2 changes: 1 addition & 1 deletion __tests__/robots.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ describe("app/robots.ts", () => {
allow: "/",
});
expect(config.rules).toContainEqual({ userAgent: "CCBot", allow: "/" });
expect(config.sitemap).toBe("https://docs.openprose.ai/sitemap.xml");
expect(config.sitemap).toBe("https://docs.prose.md/sitemap.xml");
});
});
2 changes: 1 addition & 1 deletion lib/canonical.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isPreviewMode } from "./preview-mode";

/**
* Returns the absolute canonical URL for a docs path. The path argument
* MUST start with '/'. We pin the host to docs.openprose.ai regardless of
* MUST start with '/'. We pin the host to docs.prose.md regardless of
* the actual runtime hostname, so preview deploys at openprose-docs.fly.dev
* still emit the production canonical (preventing split-indexing on cutover).
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/site.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const SITE = {
canonicalBaseUrl: "https://docs.openprose.ai",
canonicalBaseUrl: "https://docs.prose.md",
} as const;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"type": "git",
"url": "https://github.com/openprose/docs.git"
},
"homepage": "https://docs.openprose.ai",
"homepage": "https://docs.prose.md",
"packageManager": "pnpm@10.11.0",
"scripts": {
"postinstall": "fumadocs-mdx",
Expand Down
20 changes: 20 additions & 0 deletions proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,27 @@ const { rewrite: rewriteSuffix } = rewritePath(
`${docsContentRoute}{/*path}/content.md`,
);

export function resolveDocsHostRedirect(
host: string,
pathWithSearch: string,
): string | null {
const hostname = host.split(':')[0];

if (hostname !== 'docs.openprose.ai') return null;

return `https://docs.prose.md${pathWithSearch}`;
}

export default function proxy(request: NextRequest) {
const hostRedirect = resolveDocsHostRedirect(
request.headers.get('host') ?? '',
`${request.nextUrl.pathname}${request.nextUrl.search}`,
);

if (hostRedirect) {
return NextResponse.redirect(hostRedirect, 301);
}

const result = rewriteSuffix(request.nextUrl.pathname);
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl));
Expand Down
Loading