first commit

This commit is contained in:
mstfyldz
2026-06-03 16:13:15 +03:00
parent a3b76fa65d
commit 716bad9d7c
40 changed files with 2698 additions and 135 deletions
+37
View File
@@ -0,0 +1,37 @@
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { i18n } from './app/dictionaries';
function getLocale(request: NextRequest): string {
// Always return default locale for now (can be improved to read headers)
return i18n.defaultLocale;
}
export function proxy(request: NextRequest) {
const pathname = request.nextUrl.pathname;
// Skip public files and _next requests
if (
pathname.startsWith('/_next') ||
pathname.includes('.') ||
pathname.startsWith('/api')
) {
return;
}
// Check if there is any supported locale in the pathname
const pathnameIsMissingLocale = i18n.locales.every(
(locale) => !pathname.startsWith(`/${locale}/`) && pathname !== `/${locale}`
);
if (pathnameIsMissingLocale) {
const locale = getLocale(request);
return NextResponse.redirect(
new URL(`/${locale}${pathname === '/' ? '' : pathname}`, request.url)
);
}
}
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};