bug: fix rewrites to profile routes for all languages

This commit is contained in:
Christel Westerberg
2024-07-16 07:56:00 +02:00
parent 87a56448d8
commit 92829108be
2 changed files with 29 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
const myPages = {
da: "/da/webview/scandic-friends/mine-sider",
de: "/de/webview/scandic-friends/mein-profil",
de: "/de/webview/scandic-friends/mein-bereich",
en: "/en/webview/scandic-friends/my-pages",
fi: "/fi/webview/scandic-friends/minun-sivujani",
fi: "/fi/webview/scandic-friends/omat-sivut",
no: "/no/webview/scandic-friends/mine-sider",
sv: "/sv/webview/scandic-friends/mina-sidor",
}
@@ -11,7 +11,7 @@ export const overview = {
da: `${myPages.da}/oversigt`,
de: `${myPages.de}/uberblick`,
en: `${myPages.en}/overview`,
fi: `${myPages.fi}/yleiskatsaus`,
fi: `${myPages.fi}/yleista`,
no: `${myPages.no}/oversikt`,
sv: `${myPages.sv}/oversikt`,
}
@@ -20,7 +20,7 @@ export const benefits = {
da: `${myPages.da}/fordele`,
de: `${myPages.de}/vorteile`,
en: `${myPages.en}/benefits`,
fi: `${myPages.fi}/etuja`,
fi: `${myPages.fi}/edut`,
no: `${myPages.no}/fordeler`,
sv: `${myPages.sv}/formaner`,
}

View File

@@ -1,6 +1,11 @@
import { NextResponse } from "next/server"
import { myPages, overview } from "@/constants/routes/myPages"
import {
myPages,
overview,
profile,
profileEdit,
} from "@/constants/routes/myPages"
import { env } from "@/env/server"
import { internalServerError, notFound } from "@/server/errors/next"
@@ -43,6 +48,25 @@ export const middleware: NextMiddleware = async (request) => {
const headers = getDefaultRequestHeaders(request)
headers.set("x-uid", uid)
headers.set("x-contenttype", contentType)
// Handle profile and profile edit routes, which are not CMS entries
if (profile[lang].startsWith(nextUrl.pathname)) {
return NextResponse.rewrite(new URL(`/${lang}/my-pages/profile`, nextUrl), {
request: {
headers,
},
})
} else if (profileEdit[lang].startsWith(nextUrl.pathname)) {
return NextResponse.rewrite(
new URL(`/${lang}/my-pages/profile/edit`, nextUrl),
{
request: {
headers,
},
}
)
}
return NextResponse.next({
request: {
headers,