Skip to content

Commit 54c7da9

Browse files
committed
fix(i18n): align middleware with Cloudflare routing
1 parent abcb6fa commit 54c7da9

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

src/middleware.ts

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,10 @@
1-
import type { NextRequest } from 'next/server'
21
import createMiddleware from 'next-intl/middleware'
3-
import { defaultLocale, locales } from './i18n/config'
2+
import { routing } from './i18n/routing'
43

5-
const intlMiddleware = createMiddleware({
6-
// A list of all locales that are supported
7-
locales,
8-
9-
// Used when no locale matches
10-
defaultLocale,
11-
12-
// Don't prefix the default locale (English)
13-
localePrefix: 'as-needed',
14-
15-
// Detect locale from Accept-Language header
16-
localeDetection: true,
17-
})
18-
19-
export default function middleware(request: NextRequest) {
20-
// Check for stored locale preference
21-
const localeCookie = request.cookies.get('NEXT_LOCALE')
22-
if (localeCookie?.value) {
23-
// Clone the request headers and add the locale preference
24-
const requestHeaders = new Headers(request.headers)
25-
requestHeaders.set('x-locale-preference', localeCookie.value)
26-
}
27-
28-
return intlMiddleware(request)
29-
}
4+
// Next.js 16 Proxy always uses the Node.js runtime, which the current
5+
// @opennextjs/cloudflare adapter does not support for middleware yet.
6+
// Keep the legacy Edge Middleware convention until adapter support lands.
7+
export default createMiddleware(routing)
308

319
export const config = {
3210
// Match only internationalized pathnames

0 commit comments

Comments
 (0)