mirror of
https://github.com/dyzulk/trustlab-docs.git
synced 2026-01-26 05:25:38 +07:00
feat: add i18n middleware for cloudflare compatibility
This commit is contained in:
21
middleware.ts
Normal file
21
middleware.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import type { NextRequest } from 'next/server'
|
||||
|
||||
const PUBLIC_FILE = /\.(.*)$/
|
||||
|
||||
export function middleware(req: NextRequest) {
|
||||
if (
|
||||
req.nextUrl.pathname.startsWith('/_next') ||
|
||||
req.nextUrl.pathname.includes('/api/') ||
|
||||
PUBLIC_FILE.test(req.nextUrl.pathname)
|
||||
) {
|
||||
return
|
||||
}
|
||||
|
||||
if (req.nextUrl.locale === 'default') {
|
||||
const locale = req.cookies.get('NEXT_LOCALE')?.value || 'en'
|
||||
return NextResponse.redirect(
|
||||
new URL(`/${locale}${req.nextUrl.pathname}${req.nextUrl.search}`, req.url)
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user