-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
51 lines (42 loc) · 1.35 KB
/
proxy.ts
File metadata and controls
51 lines (42 loc) · 1.35 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { createI18nMiddleware } from 'fumadocs-core/i18n/middleware';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
import { type NextFetchEvent, type NextRequest, NextResponse } from 'next/server';
import { i18n } from '@/lib/i18n';
const fumadocsI18nMiddleware = createI18nMiddleware(i18n);
const { rewrite: rewriteDefaultDocsToMarkdown } = rewritePath(
'/docs{/*path}',
'/llms.mdx/docs{/*path}'
);
const { rewrite: rewriteLocalizedDocsToMarkdown } = rewritePath(
'/:lang/docs{/*path}',
'/llms.mdx/:lang/docs{/*path}'
);
const defaultLanguagePaths = [
'/',
'/docs',
'/download',
'/download/redirect',
'/blog'
];
export default function proxy(request: NextRequest, event: NextFetchEvent) {
const { pathname } = request.nextUrl;
if (isMarkdownPreferred(request)) {
const markdownPath =
rewriteDefaultDocsToMarkdown(pathname) ||
rewriteLocalizedDocsToMarkdown(pathname);
if (markdownPath) {
return NextResponse.rewrite(new URL(markdownPath, request.nextUrl));
}
}
if (
defaultLanguagePaths.includes(pathname) ||
pathname.startsWith('/docs/') ||
pathname.startsWith('/blog/')
) {
return NextResponse.next();
}
return fumadocsI18nMiddleware(request, event);
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|logo.png|.*\\..*).*)']
};