@@ -5,7 +5,7 @@ import nextConfig from './next.config.json' with { type: 'json' }
55
66import { InternalHeaders } from './lib/headers.ts'
77import { logger , LogLevel } from './lib/logging.ts'
8- import { buildNextRequest , RequestData } from './lib/next-request.ts'
8+ import { buildNextRequest , localizeRequest , RequestData } from './lib/next-request.ts'
99import { buildResponse , FetchEventResult } from './lib/response.ts'
1010import {
1111 getMiddlewareRouteMatcher ,
@@ -31,25 +31,29 @@ export async function handleMiddleware(
3131 context : Context ,
3232 nextHandler : NextHandler ,
3333) {
34- const nextRequest = buildNextRequest ( request , context , nextConfig )
3534 const url = new URL ( request . url )
35+
3636 const reqLogger = logger
3737 . withLogLevel (
3838 request . headers . has ( InternalHeaders . NFDebugLogging ) ? LogLevel . Debug : LogLevel . Log ,
3939 )
4040 . withFields ( { url_path : url . pathname } )
4141 . withRequestID ( request . headers . get ( InternalHeaders . NFRequestID ) )
4242
43+ const { localizedUrl } = localizeRequest ( url , nextConfig )
4344 // While we have already checked the path when mapping to the edge function,
4445 // Next.js supports extra rules that we need to check here too, because we
4546 // might be running an edge function for a path we should not. If we find
4647 // that's the case, short-circuit the execution.
47- if ( ! matchesMiddleware ( url . pathname , request , searchParamsToUrlQuery ( url . searchParams ) ) ) {
48+ if (
49+ ! matchesMiddleware ( localizedUrl . pathname , request , searchParamsToUrlQuery ( url . searchParams ) )
50+ ) {
4851 reqLogger . debug ( 'Aborting middleware due to runtime rules' )
4952
5053 return
5154 }
5255
56+ const nextRequest = buildNextRequest ( request , context , nextConfig )
5357 try {
5458 const result = await nextHandler ( { request : nextRequest } )
5559 const response = await buildResponse ( {
0 commit comments