(request: NextRequest)
| 25 | ] |
| 26 | |
| 27 | export function middleware(request: NextRequest) { |
| 28 | const { pathname } = request.nextUrl |
| 29 | |
| 30 | console.log('pathname', pathname) |
| 31 | |
| 32 | // Redirect /docs directly to /components |
| 33 | if (pathname === '/docs') { |
| 34 | return NextResponse.redirect(new URL('/components', request.url)) |
| 35 | } |
| 36 | |
| 37 | // If any path starts with /docs, rewrite it by removing the /docs prefix |
| 38 | if (pathname.startsWith('/docs/')) { |
| 39 | const newPathname = pathname.replace('/docs', '') |
| 40 | return NextResponse.redirect(new URL(newPathname, request.url)) |
| 41 | } |
| 42 | |
| 43 | // Check if any redirects match the current path |
| 44 | for (const redirect of redirects) { |
| 45 | if (pathname.startsWith(redirect.from)) { |
| 46 | return NextResponse.redirect(new URL(redirect.to, request.url)) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // Continue processing for other paths |
| 51 | return NextResponse.next() |
| 52 | } |
| 53 | |
| 54 | // Applies to any route that starts with /docs or just /docs |
| 55 | export const config = { |
nothing calls this directly
no outgoing calls
no test coverage detected