Skip to content

Instantly share code, notes, and snippets.

@estevan-ulian
Last active June 28, 2024 13:16
Show Gist options
  • Save estevan-ulian/be2e98b51d6e15ba2507a25e629c4630 to your computer and use it in GitHub Desktop.
Save estevan-ulian/be2e98b51d6e15ba2507a25e629c4630 to your computer and use it in GitHub Desktop.
Creates middleware to pass the site's current domain via headers
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