1
Fork 0
mirror of https://github.com/Steffo99/todocolors.git synced 2024-11-25 17:54:18 +00:00
todocolors/todoblue/src/middleware.ts

25 lines
893 B
TypeScript
Raw Normal View History

import {AVAILABLE_LOCALES} from "@/app/(i18n)/(locales)"
2023-09-29 07:32:42 +00:00
import Negotiator from "negotiator"
import {NextRequest, NextResponse} from "next/server"
2023-09-29 07:32:42 +00:00
export function middleware(request: NextRequest) {
// https://nextjs.org/docs/app/building-your-application/routing/internationalization
const pathname = request.nextUrl.pathname
const pathnameIsMissingLocale = AVAILABLE_LOCALES.every(
(locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
)
if(!pathnameIsMissingLocale) {
return NextResponse.next()
}
const negotiator = new Negotiator(request as any)
const bestLocale = negotiator.language(AVAILABLE_LOCALES)
return NextResponse.rewrite(`${request.nextUrl.protocol}//${request.nextUrl.host}/${bestLocale}${pathname}`)
}
export const config = {
matcher: [
2023-08-08 02:30:03 +00:00
'/((?!api|_next|manifest.json|logo-[nw]bg-[0-9]*.png|favicon-[nw]bg.ico).*)',
]
}