(req: NextRequest)
| 45 | }; |
| 46 | |
| 47 | const getMarkdownResponse = (req: NextRequest): NextResponse => { |
| 48 | const { pathname } = req.nextUrl; |
| 49 | |
| 50 | if (!pathname.startsWith(POSTS_PREFIX)) { |
| 51 | return NextResponse.next(); |
| 52 | } |
| 53 | |
| 54 | const id = pathname.slice(POSTS_PREFIX.length); |
| 55 | |
| 56 | // `.md` URLs are handled by the beforeFiles rewrite, which runs after |
| 57 | // proxy. Rewriting here too would pass the id along with its suffix. |
| 58 | if ( |
| 59 | !id || |
| 60 | id.endsWith('.md') || |
| 61 | RESERVED_POST_SLUGS.includes(id) || |
| 62 | !acceptsMarkdown(req.headers.get('accept')) |
| 63 | ) { |
| 64 | return NextResponse.next(); |
| 65 | } |
| 66 | |
| 67 | const url = req.nextUrl.clone(); |
| 68 | url.pathname = `${POST_MARKDOWN_PATH}/${id}`; |
| 69 | |
| 70 | return NextResponse.rewrite(url); |
| 71 | }; |
| 72 | |
| 73 | const handleMarkdownRequest = async ( |
| 74 | req: NextRequest, |
no test coverage detected