generated from CaliCastle/cali-fm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
34 lines (26 loc) · 1.1 KB
/
middleware.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { NextRequest, NextResponse } from 'next/server'
import createIntlMiddleware from 'next-intl/middleware'
import { i18n } from './i18n'
export default async function middleware(request: NextRequest) {
// Step 1: Use the incoming request
const defaultLocale = request.headers.get('x-default-locale') || 'en'
if (request.nextUrl.pathname.endsWith('/opengraph-image')) {
return NextResponse.next()
}
// Step 2: Create and call the next-intl middleware
const handleI18nRouting = createIntlMiddleware({
// A list of all locales that are supported
locales: i18n.locales,
// If this locale is matched, pathnames work without a prefix (e.g. `/about`)
defaultLocale: i18n.defaultLocale,
})
const response = handleI18nRouting(request)
// Step 3: Alter the response
response.headers.set('x-default-locale', defaultLocale)
return response
}
export const config = {
// Skip all paths that should not be internationalized. This example skips the
// folders "api", "_next" and all files with an extension (e.g. favicon.ico)
matcher: ['/((?!api|studio|_vercel|_next|.*\\..*).*)'],
}