@@ -5,13 +5,7 @@ import { updateModifiedHeaders } from './headers.ts'
5
5
import type { StructuredLogger } from './logging.ts'
6
6
import { addMiddlewareHeaders , isMiddlewareRequest , isMiddlewareResponse } from './middleware.ts'
7
7
import { NetlifyNextRequest } from './next-request.ts'
8
- import {
9
- addBasePath ,
10
- normalizeDataUrl ,
11
- normalizeLocalePath ,
12
- normalizeTrailingSlash ,
13
- relativizeURL ,
14
- } from './util.ts'
8
+ import { normalizeDataUrl , normalizeTrailingSlash , relativizeURL } from './util.ts'
15
9
16
10
export interface FetchEventResult {
17
11
response : Response
@@ -187,26 +181,12 @@ export const buildResponse = async ({
187
181
// respect trailing slash rules to prevent 308s
188
182
rewriteUrl . pathname = normalizeTrailingSlash ( rewriteUrl . pathname , nextConfig ?. trailingSlash )
189
183
190
- const target = normalizeLocalizedTarget ( { target : rewriteUrl . toString ( ) , request, nextConfig } )
191
- if ( target === request . url ) {
192
- logger . withFields ( { rewrite_url : rewrite } ) . debug ( 'Rewrite url is same as original url' )
193
- return
194
- }
184
+ const target = rewriteUrl . toString ( )
195
185
res . headers . set ( 'x-middleware-rewrite' , relativeUrl )
196
186
request . headers . set ( 'x-middleware-rewrite' , target )
197
187
return addMiddlewareHeaders ( context . rewrite ( target ) , res )
198
188
}
199
189
200
- // If we are redirecting a request that had a locale in the URL, we need to add it back in
201
- if ( redirect && locale ) {
202
- redirect = normalizeLocalizedTarget ( { target : redirect , request, nextConfig } )
203
- if ( redirect === request . url ) {
204
- logger . withFields ( { rewrite_url : rewrite } ) . debug ( 'Rewrite url is same as original url' )
205
- return
206
- }
207
- res . headers . set ( 'location' , redirect )
208
- }
209
-
210
190
// Data requests shouldn't automatically redirect in the browser (they might be HTML pages): they're handled by the router
211
191
if ( redirect && isDataReq ) {
212
192
res . headers . delete ( 'location' )
@@ -226,35 +206,3 @@ export const buildResponse = async ({
226
206
227
207
return res
228
208
}
229
-
230
- /**
231
- * Normalizes the locale in a URL.
232
- */
233
- function normalizeLocalizedTarget ( {
234
- target,
235
- request,
236
- nextConfig,
237
- locale,
238
- } : {
239
- target : string
240
- request : Request
241
- nextConfig ?: NetlifyNextRequest [ 'nextConfig' ]
242
- locale ?: string
243
- } ) {
244
- const targetUrl = new URL ( target , request . url )
245
- const normalizedTarget = normalizeLocalePath ( targetUrl . pathname , nextConfig ?. i18n ?. locales )
246
- const targetPathname = normalizedTarget . pathname
247
- const targetLocale = normalizedTarget . detectedLocale ?? locale
248
-
249
- if (
250
- targetLocale &&
251
- ! targetPathname . startsWith ( `/api/` ) &&
252
- ! targetPathname . startsWith ( `/_next/static/` )
253
- ) {
254
- targetUrl . pathname =
255
- addBasePath ( `/${ targetLocale } ${ targetPathname } ` , nextConfig ?. basePath ) || `/`
256
- } else {
257
- targetUrl . pathname = addBasePath ( targetPathname , nextConfig ?. basePath ) || `/`
258
- }
259
- return targetUrl . toString ( )
260
- }
0 commit comments