MED-154: redirect homepage to website in production. support lang param

MED-154: redirect homepage to website in production. support lang param
This commit is contained in:
danelkungla
2025-09-09 15:49:16 +03:00
committed by GitHub
2 changed files with 15 additions and 0 deletions

View File

@@ -27,6 +27,8 @@ const getUser = (request: NextRequest, response: NextResponse) => {
export async function middleware(request: NextRequest) { export async function middleware(request: NextRequest) {
const secureHeaders = await createResponseWithSecureHeaders(); const secureHeaders = await createResponseWithSecureHeaders();
const response = NextResponse.next(secureHeaders); const response = NextResponse.next(secureHeaders);
const url = new URL(request.url);
const lang = url.searchParams.get('lang');
// set a unique request ID for each request // set a unique request ID for each request
// this helps us log and trace requests // this helps us log and trace requests
@@ -35,6 +37,10 @@ export async function middleware(request: NextRequest) {
// apply CSRF protection for mutating requests // apply CSRF protection for mutating requests
const csrfResponse = await withCsrfMiddleware(request, response); const csrfResponse = await withCsrfMiddleware(request, response);
if (lang) {
csrfResponse.cookies.set('lang', lang);
}
// handle patterns for specific routes // handle patterns for specific routes
const handlePattern = matchUrlPattern(request.url); const handlePattern = matchUrlPattern(request.url);
@@ -176,6 +182,14 @@ function getPatterns() {
return NextResponse.redirect( return NextResponse.redirect(
new URL(pathsConfig.app.home, req.nextUrl.origin).href, new URL(pathsConfig.app.home, req.nextUrl.origin).href,
); );
} else if (
!['test', 'localhost'].some((pathString) =>
process.env.NEXT_PUBLIC_SITE_URL?.includes(pathString),
)
) {
return NextResponse.redirect(
new URL('https://medreport.ee', req.nextUrl.origin).href,
);
} }
}, },
}, },

View File

@@ -53,6 +53,7 @@ export function LanguageSelector({
} }
if (!userId) { if (!userId) {
localStorage.setItem('lang', locale);
return i18n.changeLanguage(locale); return i18n.changeLanguage(locale);
} }