Last active
June 28, 2024 13:16
-
-
Save estevan-ulian/be2e98b51d6e15ba2507a25e629c4630 to your computer and use it in GitHub Desktop.
Creates middleware to pass the site's current domain via headers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextFetchEvent, NextRequest, NextResponse } from "next/server"; | |
import { CustomMiddleware } from "./chain"; | |
export function xCurrentDomain(middleware: CustomMiddleware) { | |
return async (req: NextRequest, ev: NextFetchEvent) => { | |
const headers = new Headers(req.headers); | |
headers.set("x-current-domain", req.nextUrl.origin); | |
const response = NextResponse.next({ | |
request: { | |
headers, | |
}, | |
}); | |
return middleware(req, ev, response); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment