-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathproxy.ts
More file actions
25 lines (20 loc) · 844 Bytes
/
proxy.ts
File metadata and controls
25 lines (20 loc) · 844 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
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 { rewrite: rewriteLLM } = rewritePath('/docs/*path', '/llms.mdx/*path')
const i18nProxy = createI18nMiddleware(i18n)
export default function proxy(request: NextRequest, event: NextFetchEvent) {
if (isMarkdownPreferred(request)) {
const result = rewriteLLM(request.nextUrl.pathname)
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl))
}
}
return i18nProxy(request, event)
}
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon|static|robots.txt|sitemap.xml|llms.txt|llms-full.txt).*)',
],
}