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:
25
apps/partner-sas/middlewares/trailingSlash.ts
Normal file
25
apps/partner-sas/middlewares/trailingSlash.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { type NextMiddleware, NextResponse } from "next/server"
|
||||
|
||||
import { getPublicNextURL } from "@/server/utils"
|
||||
|
||||
import { getDefaultRequestHeaders } from "./utils"
|
||||
|
||||
import type { MiddlewareMatcher } from "./types"
|
||||
|
||||
export const middleware: NextMiddleware = async (request) => {
|
||||
const headers = getDefaultRequestHeaders(request)
|
||||
|
||||
const newUrl = new URL(
|
||||
request.nextUrl.pathname.slice(0, -1),
|
||||
getPublicNextURL(request)
|
||||
)
|
||||
|
||||
return NextResponse.redirect(newUrl, {
|
||||
headers,
|
||||
status: 308,
|
||||
})
|
||||
}
|
||||
|
||||
export const matcher: MiddlewareMatcher = (request) => {
|
||||
return request.nextUrl.pathname.endsWith("/")
|
||||
}
|
||||
Reference in New Issue
Block a user