mirror of
https://github.com/dyzulk/trustlab-docs.git
synced 2026-01-25 21:18:46 +07:00
22 lines
570 B
TypeScript
22 lines
570 B
TypeScript
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)
|
|
)
|
|
}
|
|
}
|