Loading examples/next-integration/lib/utils.ts 0 → 100644 +19 −0 Original line number Diff line number Diff line /** * Replaces the host of the request with the value of the * x-forwarded-host header, if present. * If don't use proxy or tunnel, this wrapper is unnecessary. * @param handler The request handler to wrap. * @return A new request handler with the host replaced. */ export function replaceHost(handler: (request: Request) => unknown) { return (request: Request) => { const forwardedHost = request.headers.get("x-forwarded-host"); if (!forwardedHost) return handler(request); const headers = new Headers(request.headers); headers.append("host", forwardedHost); const url = new URL(request.url); url.host = forwardedHost; url.port = ""; return handler(new Request(url, { ...request, headers })); }; } examples/next-integration/middleware.ts +10 −7 Original line number Diff line number Diff line import { fedifyWith } from "@fedify/next"; import federation from "@/federation"; import { replaceHost } from "./lib/utils"; export default fedifyWith(federation)( export default replaceHost( fedifyWith(federation)( /* function(request: Request){ // Add any additional middleware here return NextResponse.next() } */ ), ); // This config makes middleware process only requests with the Loading Loading
examples/next-integration/lib/utils.ts 0 → 100644 +19 −0 Original line number Diff line number Diff line /** * Replaces the host of the request with the value of the * x-forwarded-host header, if present. * If don't use proxy or tunnel, this wrapper is unnecessary. * @param handler The request handler to wrap. * @return A new request handler with the host replaced. */ export function replaceHost(handler: (request: Request) => unknown) { return (request: Request) => { const forwardedHost = request.headers.get("x-forwarded-host"); if (!forwardedHost) return handler(request); const headers = new Headers(request.headers); headers.append("host", forwardedHost); const url = new URL(request.url); url.host = forwardedHost; url.port = ""; return handler(new Request(url, { ...request, headers })); }; }
examples/next-integration/middleware.ts +10 −7 Original line number Diff line number Diff line import { fedifyWith } from "@fedify/next"; import federation from "@/federation"; import { replaceHost } from "./lib/utils"; export default fedifyWith(federation)( export default replaceHost( fedifyWith(federation)( /* function(request: Request){ // Add any additional middleware here return NextResponse.next() } */ ), ); // This config makes middleware process only requests with the Loading