another step

This commit is contained in:
hamid
2026-06-18 01:42:14 +03:30
parent e135b0b919
commit 6294cb4248
14 changed files with 70 additions and 101 deletions
+17 -2
View File
@@ -2,7 +2,7 @@ import createMiddleware from 'next-intl/middleware';
import { type NextRequest, NextResponse } from 'next/server';
import { routing } from './src/i18n/routing';
import { COOKIE_NAMES } from './src/lib/cookies';
import { PUBLIC_PATHS, ROUTES } from './src/constants';
import { HEADER_NAMES, PUBLIC_PATHS, ROUTES } from './src/constants';
const intlMiddleware = createMiddleware(routing);
@@ -39,7 +39,22 @@ export default function middleware(request: NextRequest) {
}
}
return i18nResponse;
// Detect locale from the normalized URL (next-intl always puts it at position 1)
const locale = routing.locales.find(
(l) => pathname === `/${l}` || pathname.startsWith(`/${l}/`),
) ?? routing.defaultLocale;
const requestHeaders = new Headers(request.headers);
requestHeaders.set(HEADER_NAMES.LOCALE, locale);
const response = NextResponse.next({ request: { headers: requestHeaders } });
// Preserve response headers set by next-intl (e.g. Link: alternate hreflang)
i18nResponse.headers.forEach((value, key) => {
response.headers.set(key, value);
});
return response;
}
export const config = {