-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathproxy.js
More file actions
26 lines (20 loc) · 932 Bytes
/
Copy pathproxy.js
File metadata and controls
26 lines (20 loc) · 932 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
import { NextResponse } from 'next/server'
const markdownPaths = new Set(['/', '/resume', '/recommendations', '/posts'])
export function proxy(request) {
const accept = request.headers.get('accept') ?? ''
const pathname = request.nextUrl.pathname
const isPublicArticle = /^\/posts\/[a-z0-9-]+$/.test(pathname)
const supportsMarkdown = markdownPaths.has(pathname) || isPublicArticle
if (!supportsMarkdown) return NextResponse.next()
if (!accept.includes('text/markdown')) return NextResponse.next()
const destination = new URL('/agent-markdown', request.url)
destination.searchParams.set('path', pathname)
const requestHeaders = new globalThis.Headers(request.headers)
requestHeaders.set('x-agent-markdown-path', pathname)
return NextResponse.rewrite(destination, {
request: { headers: requestHeaders }
})
}
export const config = {
matcher: ['/', '/resume', '/recommendations', '/posts/:path*']
}