Skip to content

Commit 55c7843

Browse files
authored
Merge branch 'main' into fix/track-background-revalidation
2 parents bd9771b + f4eeaa2 commit 55c7843

File tree

21 files changed

+1586
-474
lines changed

21 files changed

+1586
-474
lines changed

edge-runtime/lib/next-request.ts

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import type { Context } from '@netlify/edge-functions'
22

3-
import { addBasePath, normalizeDataUrl, normalizeLocalePath, removeBasePath } from './util.ts'
3+
import {
4+
addBasePath,
5+
addTrailingSlash,
6+
normalizeDataUrl,
7+
normalizeLocalePath,
8+
removeBasePath,
9+
} from './util.ts'
410

511
interface I18NConfig {
612
defaultLocale: string
@@ -41,43 +47,25 @@ const normalizeRequestURL = (
4147
): { url: string; detectedLocale?: string } => {
4248
const url = new URL(originalURL)
4349

44-
url.pathname = removeBasePath(url.pathname, nextConfig?.basePath)
45-
const didRemoveBasePath = url.toString() !== originalURL
50+
let pathname = removeBasePath(url.pathname, nextConfig?.basePath)
4651

47-
let detectedLocale: string | undefined
48-
49-
if (nextConfig?.i18n) {
50-
const { pathname, detectedLocale: detected } = normalizeLocalePath(
51-
url.pathname,
52-
nextConfig?.i18n?.locales,
53-
)
54-
if (!nextConfig?.skipMiddlewareUrlNormalize) {
55-
url.pathname = pathname || '/'
56-
}
57-
detectedLocale = detected
58-
}
52+
// If it exists, remove the locale from the URL and store it
53+
const { detectedLocale } = normalizeLocalePath(pathname, nextConfig?.i18n?.locales)
5954

6055
if (!nextConfig?.skipMiddlewareUrlNormalize) {
6156
// We want to run middleware for data requests and expose the URL of the
6257
// corresponding pages, so we have to normalize the URLs before running
6358
// the handler.
64-
url.pathname = normalizeDataUrl(url.pathname)
59+
pathname = normalizeDataUrl(pathname)
6560

6661
// Normalizing the trailing slash based on the `trailingSlash` configuration
6762
// property from the Next.js config.
68-
if (nextConfig?.trailingSlash && url.pathname !== '/' && !url.pathname.endsWith('/')) {
69-
url.pathname = `${url.pathname}/`
63+
if (nextConfig?.trailingSlash) {
64+
pathname = addTrailingSlash(pathname)
7065
}
7166
}
7267

73-
if (didRemoveBasePath) {
74-
url.pathname = addBasePath(url.pathname, nextConfig?.basePath)
75-
}
76-
77-
// keep the locale in the url for request.nextUrl object
78-
if (detectedLocale) {
79-
url.pathname = `/${detectedLocale}${url.pathname}`
80-
}
68+
url.pathname = addBasePath(pathname, nextConfig?.basePath)
8169

8270
return {
8371
url: url.toString(),

0 commit comments

Comments
 (0)