feat(WEB-38, WEB-9, WEB-19): add static page for sponsoring, add Header and add Footer
This commit is contained in:
62
middleware.ts
Normal file
62
middleware.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
// This function can be marked `async` if using `await` inside
|
||||
export async function middleware(request: NextRequest) {
|
||||
// const locales = await fetch(CMS_API, {
|
||||
// locales: true
|
||||
// })
|
||||
const locales = ["en", "sv", "no", "fi", "da", "de"];
|
||||
|
||||
const locale = locales.find(
|
||||
(locale) =>
|
||||
request.nextUrl.pathname.startsWith(`/${locale}/`) ||
|
||||
request.nextUrl.pathname === `/${locale}`
|
||||
);
|
||||
|
||||
if (!locale) {
|
||||
//return <LocalePicker />
|
||||
return Response.json("Not found!!!", { status: 404 });
|
||||
}
|
||||
|
||||
// const data = await fetch(CMS_API, {
|
||||
// uri: request.nextUrl.pathname,
|
||||
// locale
|
||||
// }).json()
|
||||
|
||||
//const contentType = data.response.meta.contentType;
|
||||
const contentType = "currentContentPage";
|
||||
|
||||
const pathNameWithoutLocale = request.nextUrl.pathname.replace(
|
||||
`/${locale}`,
|
||||
""
|
||||
);
|
||||
|
||||
const searchParams = new URLSearchParams(request.nextUrl.searchParams)
|
||||
searchParams.set("uri", pathNameWithoutLocale)
|
||||
|
||||
switch (contentType) {
|
||||
case "currentContentPage":
|
||||
return NextResponse.rewrite(
|
||||
new URL(
|
||||
`/${locale}/current-content-page?${searchParams.toString()}`,
|
||||
request.url
|
||||
)
|
||||
);
|
||||
}
|
||||
return NextResponse.redirect(new URL("/home", request.url));
|
||||
}
|
||||
|
||||
// See "Matching Paths" below to learn more
|
||||
export const config = {
|
||||
matcher: [
|
||||
/*
|
||||
* Match all request paths except for the ones starting with:
|
||||
* - api (API routes)
|
||||
* - _next/static (static files)
|
||||
* - _next/image (image optimization files)
|
||||
* - favicon.ico (favicon file)
|
||||
*/
|
||||
"/((?!api|_next/static|_next/image|Static|imageVault|contentassets|favicon.ico).*)",
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user