Files

32 lines
880 B
TypeScript

import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
const locales = ["tr", "en"];
const defaultLocale = "tr";
export function proxy(request: NextRequest) {
// Check if there is any supported locale in the pathname
const { pathname } = request.nextUrl;
if (pathname.startsWith('/admin')) {
return;
}
const pathnameHasLocale = locales.some(
(locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`
);
if (pathnameHasLocale) return;
// If no locale found, redirect to default locale
request.nextUrl.pathname = `/${defaultLocale}${pathname}`;
return NextResponse.redirect(request.nextUrl);
}
export const config = {
matcher: [
// Skip all internal paths (_next) and static files
'/((?!api|_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)',
],
};