forked from LibreChat-AI/librechat.ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
24 lines (19 loc) · 672 Bytes
/
proxy.ts
File metadata and controls
24 lines (19 loc) · 672 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
import { NextRequest, NextResponse } from 'next/server'
function isMarkdownPreferred(request: NextRequest): boolean {
const accept = request.headers.get('accept') ?? ''
return accept.includes('text/markdown')
}
export default function proxy(request: NextRequest): NextResponse {
if (isMarkdownPreferred(request)) {
const { pathname } = request.nextUrl
if (pathname.startsWith('/docs')) {
const rest = pathname.slice('/docs'.length)
const rewritten = `/llms.mdx/docs${rest}`
return NextResponse.rewrite(new URL(rewritten, request.nextUrl))
}
}
return NextResponse.next()
}
export const config = {
matcher: ['/docs/:path*'],
}