-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathproxy.ts
More file actions
32 lines (26 loc) · 941 Bytes
/
proxy.ts
File metadata and controls
32 lines (26 loc) · 941 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { isMarkdownPreferred, rewritePath } from "fumadocs-core/negotiation";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { ROUTES } from "@/constants/routes";
import { docsContentRoute } from "@/lib/docs";
const { rewrite: rewriteDocs } = rewritePath(
`${ROUTES.DOCS}{/*path}`,
`${docsContentRoute}{/*path}/content.md`
);
const { rewrite: rewriteSuffix } = rewritePath(
`${ROUTES.DOCS}{/*path}.mdx`,
`${docsContentRoute}{/*path}/content.md`
);
export default function proxy(request: NextRequest) {
const result = rewriteSuffix(request.nextUrl.pathname);
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
if (isMarkdownPreferred(request)) {
const result2 = rewriteDocs(request.nextUrl.pathname);
if (result2) {
return NextResponse.rewrite(new URL(result2, request.nextUrl));
}
}
return NextResponse.next();
}