11import { NextResponse } from 'next/server'
22import type { NextRequest } from 'next/server'
33import docsConfig from '../docs.config.js'
4+
45const { updatedRedirectsData } = require ( './data/redirects.ts' ) ;
6+
57function createRedirectUrl ( request : NextRequest , destination : string , path : string ) : string {
68 // Handle absolute URLs
79 if ( destination . startsWith ( 'http' ) ) {
@@ -17,8 +19,10 @@ function createRedirectUrl(request: NextRequest, destination: string, path: stri
1719 const version = versionMatch ? versionMatch [ 0 ] : ''
1820 destination = destination . replace ( ':version' , version )
1921 }
22+
2023 return destination
2124 }
25+
2226 // Handle relative paths
2327 const basePath = '/docs'
2428 return destination . startsWith ( '/' ) ?
@@ -29,6 +33,7 @@ function createRedirectUrl(request: NextRequest, destination: string, path: stri
2933export function middleware ( request : NextRequest ) {
3034 const path = request . nextUrl . pathname
3135 const pathWithoutBase = path . replace ( '/docs' , '' )
36+
3237 // Handle base redirects from redirects.ts
3338 const redirect = updatedRedirectsData . find ( ( r : any ) => r . source === pathWithoutBase )
3439 if ( redirect ) {
@@ -72,8 +77,10 @@ export function middleware(request: NextRequest) {
7277 }
7378 if ( pathWithoutBase === '/changelog.rss' )
7479 return NextResponse . redirect ( createRedirectUrl ( request , '/technical-changelog.rss' , path ) )
80+
7581 return NextResponse . next ( )
7682}
83+
7784export const config = {
7885 matcher : [
7986 '/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js).*)' ,
0 commit comments