@feedify/next:将Fedify与Next.js整合起来
此软件包提供了一个简单的整合方式 联邦 与 下一个.js。 。 。 .
[大 我们建议您使用
init命令 合并CLI 而不是直接安装此软件包.
[大 这个软件包依赖于 Next.js 请求截取节点运行时间. 因此,你必须使用 Next.js 15.4.6 或以后. 在接下来的.j 16,
proxy.ts首选middleware.ts已贬值,但 仍然得到支持。 切换到proxy.ts,省略runtime: "nodejs"从 导出config因为代理机总是运行在节点.js运行时间. 详情请参见: 正式记录proxy。 。 。 .
使用量
// --- 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*" },
],
};
这个 matcher 决定Next.js是否运行中间软件; fedifyWith() 接下来
决定联邦是否处理请求。 节点信息路径 /nodeinfo/
无论标题如何,均转发。 升级现有时
应用程序,添加 { source: "/nodeinfo/:path*" } 联合国 matcher 以及
升级此软件包。 此前缀下的请求即使没有
调度员,返回 404 Not Found 默认.
用于外部的节点信息调度器 /nodeinfo/,将其路径添加到 matcher 财务报告和审定财务报表
明确授权它 integrateFederation() 同样的
上下文数据厂和您使用的错误处理器 fedifyWith()。 。 。 .
A 类 matcher 单输入不能使 fedifyWith() 识别自定义路径.