-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
46 lines (43 loc) · 1.31 KB
/
middleware.ts
File metadata and controls
46 lines (43 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { integrateFederation, isFederationRequest } from "@fedify/next";
import { NextResponse } from "next/server";
import { getXForwardedRequest } from "x-forwarded-fetch";
import federation from "./federation";
import "./logging";
const federationHandler = integrateFederation(federation);
export default async function middleware(request: Request) {
const forwarded = await getXForwardedRequest(request);
if (isFederationRequest(forwarded)) {
return await federationHandler(forwarded);
}
return NextResponse.next();
}
// This config needs because middleware process only requests with the
// "Accept" header matching the federation accept regex.
// More details: https://nextjs.org/docs/app/api-reference/file-conventions/middleware#config-object-optional
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" },
],
};