-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathproxy.ts
More file actions
30 lines (24 loc) · 895 Bytes
/
Copy pathproxy.ts
File metadata and controls
30 lines (24 loc) · 895 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
import { NextRequest, NextResponse } from 'next/server';
import { isMarkdownPreferred, rewritePath } from 'fumadocs-core/negotiation';
const { rewrite: rewriteLLM } = rewritePath('/docs/*path', '/llms.mdx/*path');
const SITE_URL = 'https://stately.ai';
const LINK_HEADER = [
`<${SITE_URL}/sitemap.xml>; rel="sitemap"; type="application/xml"`,
`<${SITE_URL}/llms.txt>; rel="describedby"; type="text/plain"`,
].join(', ');
export function proxy(request: NextRequest) {
if (isMarkdownPreferred(request)) {
const result = rewriteLLM(request.nextUrl.pathname);
if (result) {
return NextResponse.rewrite(new URL(result, request.nextUrl));
}
}
const response = NextResponse.next();
response.headers.append('Link', LINK_HEADER);
return response;
}
export const config = {
matcher: [
'/((?!api|_next/static|_next/image|favicon.ico|assets|.*\\..*).*)',
],
};