(req: NextRequest)
| 33 | }; |
| 34 | |
| 35 | export function proxy(req: NextRequest) { |
| 36 | const { pathname, search } = req.nextUrl; |
| 37 | |
| 38 | if (pathname.endsWith(".md") && !PASSTHROUGH_PATHS.has(pathname)) { |
| 39 | const realPath = pathname.replace(MD_SUFFIX, "") || "/"; |
| 40 | const target = toMdRewrite(realPath); |
| 41 | return NextResponse.rewrite(new URL(`${target}${search}`, req.url)); |
| 42 | } |
| 43 | |
| 44 | const accept = req.headers.get("accept") ?? ""; |
| 45 | if (!accept.includes("text/markdown")) { |
| 46 | return NextResponse.next(); |
| 47 | } |
| 48 | |
| 49 | if (isPassthrough(pathname) || FILE_EXTENSION.test(pathname)) { |
| 50 | return NextResponse.next(); |
| 51 | } |
| 52 | |
| 53 | const target = toMdRewrite(pathname); |
| 54 | return NextResponse.rewrite(new URL(`${target}${search}`, req.url)); |
| 55 | } |
| 56 | |
| 57 | export const proxyConfig = { |
| 58 | matcher: ["/((?!_next/).*)"], |
nothing calls this directly
no test coverage detected