32 lines
879 B
TypeScript
32 lines
879 B
TypeScript
import { NextResponse } from "next/server"
|
|
|
|
import { findLang } from "@/constants/languages"
|
|
import { badRequest } from "@/server/errors/next"
|
|
|
|
import type { NextMiddleware } from "next/server"
|
|
|
|
import type { MiddlewareMatcher } from "@/types/middleware"
|
|
|
|
export const middleware: NextMiddleware = (request) => {
|
|
console.log("HEJ", request)
|
|
const currentwebUrl = request.nextUrl.searchParams.get("currentweb")
|
|
if (currentwebUrl == null) {
|
|
return badRequest()
|
|
}
|
|
|
|
const lang = findLang(request.nextUrl.pathname)!
|
|
|
|
//const headers = new Headers(request.headers)
|
|
//headers.set("x-returnurl", returnUrl)
|
|
|
|
return NextResponse.rewrite(new URL(`/${lang}/logout`, request.nextUrl), {
|
|
/*request: {
|
|
headers,
|
|
},*/
|
|
})
|
|
}
|
|
|
|
export const matcher: MiddlewareMatcher = (request) => {
|
|
return request.nextUrl.pathname.endsWith("/updatelogout") //?currentweb")
|
|
}
|