Merged in feat/sw-3197-add-url-to-path (pull request #2577)
feat(SW-3197): Add required middleware and url to path in partner-sas * Add url to path and required middleware Approved-by: Matilda Landström
This commit is contained in:
22
apps/partner-sas/middlewares/utils.ts
Normal file
22
apps/partner-sas/middlewares/utils.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { findLang } from "@scandic-hotels/common/utils/languages"
|
||||
import { removeTrailingSlash } from "@scandic-hotels/common/utils/url"
|
||||
|
||||
import { getPublicNextURL } from "@/server/utils"
|
||||
|
||||
import type { NextRequest } from "next/server"
|
||||
|
||||
export function getDefaultRequestHeaders(request: NextRequest) {
|
||||
const lang = findLang(request.nextUrl.pathname)!
|
||||
const nextUrlPublic = getPublicNextURL(request)
|
||||
const headers = new Headers(request.headers)
|
||||
headers.set("x-lang", lang)
|
||||
headers.set(
|
||||
"x-pathname",
|
||||
removeTrailingSlash(
|
||||
request.nextUrl.pathname.replace(`/${lang}`, "").replace(`/webview`, "")
|
||||
)
|
||||
)
|
||||
headers.set("x-url", removeTrailingSlash(nextUrlPublic.href))
|
||||
|
||||
return headers
|
||||
}
|
||||
Reference in New Issue
Block a user