@fedify/next: Integrate Fedify with Next.js
This package provides a simple way to integrate Fedify with Next.js.
[!IMPORTANT] We recommend initializing your app using the
initcommand of the Fedify CLI rather than installing this package directly.
[!IMPORTANT] This package relies on Next.js request interception on the Node.js runtime. Therefore, you must use Next.js 15.4.6 or later. On Next.js 16,
proxy.tsis preferred andmiddleware.tsis deprecated but still supported. If you switch toproxy.ts, omitruntime: "nodejs"from the exportedconfig, because Proxy always runs on the Node.js runtime. For more details, refer to the official documentation ofproxy.
Usage
// --- middleware.ts ---
import { fedifyWith } from "@fedify/next";
import { federation } from "./federation";
export default fedifyWith(federation)();
// This config must be defined in the same file.
export const config = {
runtime: "nodejs",
matcher: [
{
source: "/:path*",
has: [
{
type: "header",
key: "Accept",
value: ".*application\\/((jrd|activity|ld)\\+json|xrd\\+xml).*",
},
],
},
{
source: "/:path*",
has: [
{
type: "header",
key: "content-type",
value: ".*application\\/((jrd|activity|ld)\\+json|xrd\\+xml).*",
},
],
},
{ source: "/.well-known/nodeinfo" },
{ source: "/.well-known/x-nodeinfo2" },
{ source: "/nodeinfo/:path*" },
],
};
The matcher decides whether Next.js runs the middleware; fedifyWith() then
decides whether Fedify handles the request. NodeInfo paths under /nodeinfo/
are forwarded regardless of their headers. When upgrading an existing
application, add { source: "/nodeinfo/:path*" } to its matcher as well as
upgrading this package. Requests under this prefix go to Fedify even without
a dispatcher, returning 404 Not Found by default.
For a NodeInfo dispatcher outside /nodeinfo/, add its path to matcher and
explicitly delegate requests for it to integrateFederation() with the same
context data factory and error handlers you use with fedifyWith().
A matcher entry alone does not make fedifyWith() recognize a custom path.