bug: fix rewrites to profile routes for all languages
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user