forked from vercel/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
33 lines (28 loc) · 983 Bytes
/
middleware.ts
File metadata and controls
33 lines (28 loc) · 983 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
33
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
import { type NextRequest, NextResponse } from 'next/server';
const { rewrite: rewriteLLM } = rewritePath('/docs/*path', '/llms.mdx/*path');
export async function middleware(request: NextRequest) {
const response = NextResponse.next();
if (isMarkdownPreferred(request)) {
const result = rewriteLLM(request.nextUrl.pathname);
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
}
return response;
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api (API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - robots.txt (robots file)
* - *.svg$ (svg files)
* - *.zip (zip files)
*/
'/((?!api|_next/static|_next/image|favicon.ico|robots.txt|.*\\.svg$|.*\\.zip).*)',
],
};