@fedify/next 2.0.36-dev.2653 → 2.0.36-dev.2734
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -0
- package/dist/index.cjs +18 -3
- package/dist/index.d.cts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +18 -3
- package/package.json +7 -4
package/README.md
CHANGED
|
@@ -63,6 +63,19 @@ export const config = {
|
|
|
63
63
|
},
|
|
64
64
|
{ source: "/.well-known/nodeinfo" },
|
|
65
65
|
{ source: "/.well-known/x-nodeinfo2" },
|
|
66
|
+
{ source: "/nodeinfo/:path*" },
|
|
66
67
|
],
|
|
67
68
|
};
|
|
68
69
|
~~~~
|
|
70
|
+
|
|
71
|
+
The `matcher` decides whether Next.js runs the middleware; `fedifyWith()` then
|
|
72
|
+
decides whether Fedify handles the request. NodeInfo paths under `/nodeinfo/`
|
|
73
|
+
are forwarded regardless of their headers. When upgrading an existing
|
|
74
|
+
application, add `{ source: "/nodeinfo/:path*" }` to its `matcher` as well as
|
|
75
|
+
upgrading this package. Requests under this prefix go to Fedify even without
|
|
76
|
+
a dispatcher, returning `404 Not Found` by default.
|
|
77
|
+
|
|
78
|
+
For a NodeInfo dispatcher outside `/nodeinfo/`, add its path to `matcher` and
|
|
79
|
+
explicitly delegate requests for it to `integrateFederation()` with the same
|
|
80
|
+
context data factory and error handlers you use with `fedifyWith()`.
|
|
81
|
+
A `matcher` entry alone does not make `fedifyWith()` recognize a custom path.
|
package/dist/index.cjs
CHANGED
|
@@ -28,8 +28,8 @@ let next_server_js = require("next/server.js");
|
|
|
28
28
|
* }
|
|
29
29
|
* )
|
|
30
30
|
*
|
|
31
|
-
* //
|
|
32
|
-
* //
|
|
31
|
+
* // Run middleware for federation media types and NodeInfo paths, including
|
|
32
|
+
* // NodeInfo documents fetched with "Accept: application/json".
|
|
33
33
|
* // More details: https://nextjs.org/docs/app/api-reference/file-conventions/middleware#config-object-optional.
|
|
34
34
|
* export const config = {
|
|
35
35
|
* runtime: "nodejs",
|
|
@@ -56,6 +56,7 @@ let next_server_js = require("next/server.js");
|
|
|
56
56
|
* },
|
|
57
57
|
* { source: "/.well-known/nodeinfo" },
|
|
58
58
|
* { source: "/.well-known/x-nodeinfo2" },
|
|
59
|
+
* { source: "/nodeinfo/:path*" },
|
|
59
60
|
* ],
|
|
60
61
|
* };
|
|
61
62
|
* ```
|
|
@@ -64,6 +65,10 @@ const fedifyWith = (federation, contextDataFactory, errorHandlers) => (middlewar
|
|
|
64
65
|
if (isFederationRequest(request)) return await integrateFederation(federation, contextDataFactory, errorHandlers)(request);
|
|
65
66
|
return await middleware(request);
|
|
66
67
|
};
|
|
68
|
+
/**
|
|
69
|
+
* Check for federation media types or a recognized NodeInfo path.
|
|
70
|
+
* NodeInfo paths are recognized regardless of the request headers.
|
|
71
|
+
*/
|
|
67
72
|
const isFederationRequest = (request) => [
|
|
68
73
|
hasFederationHeader("accept"),
|
|
69
74
|
hasFederationHeader("content-type"),
|
|
@@ -81,11 +86,21 @@ const hasFederationHeader = (key) => (request) => {
|
|
|
81
86
|
const value = request.headers.get(key);
|
|
82
87
|
return value ? FEDERATION_ACCEPT_REGEX.test(value) : false;
|
|
83
88
|
};
|
|
89
|
+
/**
|
|
90
|
+
* Check for a well-known NodeInfo path or a path under `/nodeinfo/`.
|
|
91
|
+
* This does not check whether a NodeInfo dispatcher is registered.
|
|
92
|
+
* Dispatchers at other paths require explicit delegation to
|
|
93
|
+
* {@link integrateFederation}.
|
|
94
|
+
*/
|
|
84
95
|
const isNodeInfoRequest = (request) => {
|
|
85
96
|
const url = new URL(request.url);
|
|
86
97
|
return NODEINFO_PATHS.some((path) => url.pathname.startsWith(path));
|
|
87
98
|
};
|
|
88
|
-
const NODEINFO_PATHS = [
|
|
99
|
+
const NODEINFO_PATHS = [
|
|
100
|
+
"/.well-known/nodeinfo",
|
|
101
|
+
"/.well-known/x-nodeinfo2",
|
|
102
|
+
"/nodeinfo/"
|
|
103
|
+
];
|
|
89
104
|
const FEDERATION_ACCEPT_REGEX = /.*application\/((jrd|activity|ld)\+json|xrd\+xml).*/;
|
|
90
105
|
/**
|
|
91
106
|
* Create a Next.js handler to integrate with the {@link Federation} object.
|
package/dist/index.d.cts
CHANGED
|
@@ -32,8 +32,8 @@ type ErrorHandlers = Omit<FederationFetchOptions<unknown>, "contextData">;
|
|
|
32
32
|
* }
|
|
33
33
|
* )
|
|
34
34
|
*
|
|
35
|
-
* //
|
|
36
|
-
* //
|
|
35
|
+
* // Run middleware for federation media types and NodeInfo paths, including
|
|
36
|
+
* // NodeInfo documents fetched with "Accept: application/json".
|
|
37
37
|
* // More details: https://nextjs.org/docs/app/api-reference/file-conventions/middleware#config-object-optional.
|
|
38
38
|
* export const config = {
|
|
39
39
|
* runtime: "nodejs",
|
|
@@ -60,11 +60,16 @@ type ErrorHandlers = Omit<FederationFetchOptions<unknown>, "contextData">;
|
|
|
60
60
|
* },
|
|
61
61
|
* { source: "/.well-known/nodeinfo" },
|
|
62
62
|
* { source: "/.well-known/x-nodeinfo2" },
|
|
63
|
+
* { source: "/nodeinfo/:path*" },
|
|
63
64
|
* ],
|
|
64
65
|
* };
|
|
65
66
|
* ```
|
|
66
67
|
*/
|
|
67
68
|
declare const fedifyWith: <TContextData>(federation: Federation<TContextData>, contextDataFactory?: ContextDataFactory<TContextData>, errorHandlers?: Partial<ErrorHandlers>) => (middleware?: (request: Request) => unknown) => (request: Request) => unknown;
|
|
69
|
+
/**
|
|
70
|
+
* Check for federation media types or a recognized NodeInfo path.
|
|
71
|
+
* NodeInfo paths are recognized regardless of the request headers.
|
|
72
|
+
*/
|
|
68
73
|
declare const isFederationRequest: (request: Request) => boolean;
|
|
69
74
|
/**
|
|
70
75
|
* Check if the request has the header matching the federation
|
|
@@ -75,6 +80,12 @@ declare const isFederationRequest: (request: Request) => boolean;
|
|
|
75
80
|
* the federation accept regex, `false` otherwise.
|
|
76
81
|
*/
|
|
77
82
|
declare const hasFederationHeader: (key: string) => (request: Request) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Check for a well-known NodeInfo path or a path under `/nodeinfo/`.
|
|
85
|
+
* This does not check whether a NodeInfo dispatcher is registered.
|
|
86
|
+
* Dispatchers at other paths require explicit delegation to
|
|
87
|
+
* {@link integrateFederation}.
|
|
88
|
+
*/
|
|
78
89
|
declare const isNodeInfoRequest: (request: Request) => boolean;
|
|
79
90
|
/**
|
|
80
91
|
* Create a Next.js handler to integrate with the {@link Federation} object.
|
package/dist/index.d.ts
CHANGED
|
@@ -32,8 +32,8 @@ type ErrorHandlers = Omit<FederationFetchOptions<unknown>, "contextData">;
|
|
|
32
32
|
* }
|
|
33
33
|
* )
|
|
34
34
|
*
|
|
35
|
-
* //
|
|
36
|
-
* //
|
|
35
|
+
* // Run middleware for federation media types and NodeInfo paths, including
|
|
36
|
+
* // NodeInfo documents fetched with "Accept: application/json".
|
|
37
37
|
* // More details: https://nextjs.org/docs/app/api-reference/file-conventions/middleware#config-object-optional.
|
|
38
38
|
* export const config = {
|
|
39
39
|
* runtime: "nodejs",
|
|
@@ -60,11 +60,16 @@ type ErrorHandlers = Omit<FederationFetchOptions<unknown>, "contextData">;
|
|
|
60
60
|
* },
|
|
61
61
|
* { source: "/.well-known/nodeinfo" },
|
|
62
62
|
* { source: "/.well-known/x-nodeinfo2" },
|
|
63
|
+
* { source: "/nodeinfo/:path*" },
|
|
63
64
|
* ],
|
|
64
65
|
* };
|
|
65
66
|
* ```
|
|
66
67
|
*/
|
|
67
68
|
declare const fedifyWith: <TContextData>(federation: Federation<TContextData>, contextDataFactory?: ContextDataFactory<TContextData>, errorHandlers?: Partial<ErrorHandlers>) => (middleware?: (request: Request) => unknown) => (request: Request) => unknown;
|
|
69
|
+
/**
|
|
70
|
+
* Check for federation media types or a recognized NodeInfo path.
|
|
71
|
+
* NodeInfo paths are recognized regardless of the request headers.
|
|
72
|
+
*/
|
|
68
73
|
declare const isFederationRequest: (request: Request) => boolean;
|
|
69
74
|
/**
|
|
70
75
|
* Check if the request has the header matching the federation
|
|
@@ -75,6 +80,12 @@ declare const isFederationRequest: (request: Request) => boolean;
|
|
|
75
80
|
* the federation accept regex, `false` otherwise.
|
|
76
81
|
*/
|
|
77
82
|
declare const hasFederationHeader: (key: string) => (request: Request) => boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Check for a well-known NodeInfo path or a path under `/nodeinfo/`.
|
|
85
|
+
* This does not check whether a NodeInfo dispatcher is registered.
|
|
86
|
+
* Dispatchers at other paths require explicit delegation to
|
|
87
|
+
* {@link integrateFederation}.
|
|
88
|
+
*/
|
|
78
89
|
declare const isNodeInfoRequest: (request: Request) => boolean;
|
|
79
90
|
/**
|
|
80
91
|
* Create a Next.js handler to integrate with the {@link Federation} object.
|
package/dist/index.js
CHANGED
|
@@ -27,8 +27,8 @@ import { NextResponse } from "next/server.js";
|
|
|
27
27
|
* }
|
|
28
28
|
* )
|
|
29
29
|
*
|
|
30
|
-
* //
|
|
31
|
-
* //
|
|
30
|
+
* // Run middleware for federation media types and NodeInfo paths, including
|
|
31
|
+
* // NodeInfo documents fetched with "Accept: application/json".
|
|
32
32
|
* // More details: https://nextjs.org/docs/app/api-reference/file-conventions/middleware#config-object-optional.
|
|
33
33
|
* export const config = {
|
|
34
34
|
* runtime: "nodejs",
|
|
@@ -55,6 +55,7 @@ import { NextResponse } from "next/server.js";
|
|
|
55
55
|
* },
|
|
56
56
|
* { source: "/.well-known/nodeinfo" },
|
|
57
57
|
* { source: "/.well-known/x-nodeinfo2" },
|
|
58
|
+
* { source: "/nodeinfo/:path*" },
|
|
58
59
|
* ],
|
|
59
60
|
* };
|
|
60
61
|
* ```
|
|
@@ -63,6 +64,10 @@ const fedifyWith = (federation, contextDataFactory, errorHandlers) => (middlewar
|
|
|
63
64
|
if (isFederationRequest(request)) return await integrateFederation(federation, contextDataFactory, errorHandlers)(request);
|
|
64
65
|
return await middleware(request);
|
|
65
66
|
};
|
|
67
|
+
/**
|
|
68
|
+
* Check for federation media types or a recognized NodeInfo path.
|
|
69
|
+
* NodeInfo paths are recognized regardless of the request headers.
|
|
70
|
+
*/
|
|
66
71
|
const isFederationRequest = (request) => [
|
|
67
72
|
hasFederationHeader("accept"),
|
|
68
73
|
hasFederationHeader("content-type"),
|
|
@@ -80,11 +85,21 @@ const hasFederationHeader = (key) => (request) => {
|
|
|
80
85
|
const value = request.headers.get(key);
|
|
81
86
|
return value ? FEDERATION_ACCEPT_REGEX.test(value) : false;
|
|
82
87
|
};
|
|
88
|
+
/**
|
|
89
|
+
* Check for a well-known NodeInfo path or a path under `/nodeinfo/`.
|
|
90
|
+
* This does not check whether a NodeInfo dispatcher is registered.
|
|
91
|
+
* Dispatchers at other paths require explicit delegation to
|
|
92
|
+
* {@link integrateFederation}.
|
|
93
|
+
*/
|
|
83
94
|
const isNodeInfoRequest = (request) => {
|
|
84
95
|
const url = new URL(request.url);
|
|
85
96
|
return NODEINFO_PATHS.some((path) => url.pathname.startsWith(path));
|
|
86
97
|
};
|
|
87
|
-
const NODEINFO_PATHS = [
|
|
98
|
+
const NODEINFO_PATHS = [
|
|
99
|
+
"/.well-known/nodeinfo",
|
|
100
|
+
"/.well-known/x-nodeinfo2",
|
|
101
|
+
"/nodeinfo/"
|
|
102
|
+
];
|
|
88
103
|
const FEDERATION_ACCEPT_REGEX = /.*application\/((jrd|activity|ld)\+json|xrd\+xml).*/;
|
|
89
104
|
/**
|
|
90
105
|
* Create a Next.js handler to integrate with the {@link Federation} object.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/next",
|
|
3
|
-
"version": "2.0.36-dev.
|
|
3
|
+
"version": "2.0.36-dev.2734+3364869b",
|
|
4
4
|
"description": "Integrate Fedify with Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -51,15 +51,18 @@
|
|
|
51
51
|
],
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"next": ">=15.4.6 <17",
|
|
54
|
-
"@fedify/fedify": "^2.0.36-dev.
|
|
54
|
+
"@fedify/fedify": "^2.0.36-dev.2734+3364869b"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"tsdown": "^0.21.6",
|
|
58
|
-
"typescript": "^6.0.0"
|
|
58
|
+
"typescript": "^6.0.0",
|
|
59
|
+
"@fedify/fixture": "2.0.0"
|
|
59
60
|
},
|
|
60
61
|
"scripts": {
|
|
61
62
|
"build:self": "tsdown",
|
|
62
63
|
"build": "pnpm --filter @fedify/next... run build:self",
|
|
63
|
-
"prepublish": "pnpm build"
|
|
64
|
+
"prepublish": "pnpm build",
|
|
65
|
+
"test": "pnpm build:self && node --test dist-tests/index.test.cjs",
|
|
66
|
+
"test:bun": "bun test ./src/index.test.ts"
|
|
64
67
|
}
|
|
65
68
|
}
|