@fedify/hono 2.0.0-dev.1566 → 2.0.0-dev.159
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/LICENSE +1 -1
- package/README.md +16 -14
- package/dist/mod.cjs +46 -0
- package/dist/mod.d.cts +39 -0
- package/package.json +12 -14
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -26,6 +26,16 @@ const app = new Hono();
|
|
|
26
26
|
app.use(federation(fedi, (ctx) => "context data"));
|
|
27
27
|
~~~~
|
|
28
28
|
|
|
29
|
+
[JSR badge]: https://jsr.io/badges/@fedify/hono
|
|
30
|
+
[JSR]: https://jsr.io/@fedify/hono
|
|
31
|
+
[npm badge]: https://img.shields.io/npm/v/@fedify/hono?logo=npm
|
|
32
|
+
[npm]: https://www.npmjs.com/package/@fedify/hono
|
|
33
|
+
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
34
|
+
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
35
|
+
[Fedify]: https://fedify.dev/
|
|
36
|
+
[Hono]: https://hono.dev/
|
|
37
|
+
|
|
38
|
+
|
|
29
39
|
How it works
|
|
30
40
|
------------
|
|
31
41
|
|
|
@@ -37,12 +47,13 @@ application to coexist in the same domain and port.
|
|
|
37
47
|
|
|
38
48
|
For example, if you make a request to */.well-known/webfinger* Fedify will
|
|
39
49
|
handle the request by itself, but if you make a request to */users/alice*
|
|
40
|
-
(assuming your Hono app has a handler for `/users/:handle`) with
|
|
41
|
-
text/html` header, Fedify will dispatch the request to the Hono app's
|
|
50
|
+
(assuming your Hono app has a handler for `/users/:handle`) with
|
|
51
|
+
`Accept: text/html` header, Fedify will dispatch the request to the Hono app's
|
|
42
52
|
appropriate handler for `/users/:handle`. Or if you define an actor dispatcher
|
|
43
|
-
for `/users/{handle}` in Fedify, and the request is made with
|
|
44
|
-
application/activity+json` header, Fedify will dispatch the request to
|
|
45
|
-
appropriate actor dispatcher.
|
|
53
|
+
for `/users/{handle}` in Fedify, and the request is made with
|
|
54
|
+
`Accept: application/activity+json` header, Fedify will dispatch the request to
|
|
55
|
+
the appropriate actor dispatcher.
|
|
56
|
+
|
|
46
57
|
|
|
47
58
|
Installation
|
|
48
59
|
------------
|
|
@@ -54,12 +65,3 @@ pnpm add @fedify/hono # pnpm
|
|
|
54
65
|
yarn add @fedify/hono # Yarn
|
|
55
66
|
bun add @fedify/hono # Bun
|
|
56
67
|
~~~~
|
|
57
|
-
|
|
58
|
-
[JSR]: https://jsr.io/@fedify/hono
|
|
59
|
-
[JSR badge]: https://jsr.io/badges/@fedify/hono
|
|
60
|
-
[npm]: https://www.npmjs.com/package/@fedify/hono
|
|
61
|
-
[npm badge]: https://img.shields.io/npm/v/@fedify/hono?logo=npm
|
|
62
|
-
[@fedify@hollo.social badge]: https://fedi-badge.deno.dev/@fedify@hollo.social/followers.svg
|
|
63
|
-
[@fedify@hollo.social]: https://hollo.social/@fedify
|
|
64
|
-
[Fedify]: https://fedify.dev/
|
|
65
|
-
[Hono]: https://hono.dev/
|
package/dist/mod.cjs
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/mod.ts
|
|
3
|
+
/**
|
|
4
|
+
* Create a Hono middleware to integrate with the {@link Federation} object.
|
|
5
|
+
*
|
|
6
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
7
|
+
* object.
|
|
8
|
+
* @template THonoContext A type of the Hono context.
|
|
9
|
+
* @param federation A {@link Federation} object to integrate with Hono.
|
|
10
|
+
* @param contextDataFactory A function to create a context data for the
|
|
11
|
+
* {@link Federation} object.
|
|
12
|
+
* @returns A Hono middleware.
|
|
13
|
+
* @since 1.9.0
|
|
14
|
+
*/
|
|
15
|
+
function federation(federation$1, contextDataFactory) {
|
|
16
|
+
return async (ctx, next) => {
|
|
17
|
+
let contextData = contextDataFactory(ctx);
|
|
18
|
+
if (contextData instanceof Promise) contextData = await contextData;
|
|
19
|
+
return await federation$1.fetch(ctx.req.raw, {
|
|
20
|
+
contextData,
|
|
21
|
+
...integrateFetchOptions(ctx, next)
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function integrateFetchOptions(ctx, next) {
|
|
26
|
+
return {
|
|
27
|
+
async onNotFound(_req) {
|
|
28
|
+
await next();
|
|
29
|
+
return ctx.res;
|
|
30
|
+
},
|
|
31
|
+
async onNotAcceptable(_req) {
|
|
32
|
+
await next();
|
|
33
|
+
if (ctx.res.status !== 404) return ctx.res;
|
|
34
|
+
return new Response("Not acceptable", {
|
|
35
|
+
status: 406,
|
|
36
|
+
headers: {
|
|
37
|
+
"Content-Type": "text/plain",
|
|
38
|
+
Vary: "Accept"
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
exports.federation = federation;
|
package/dist/mod.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Federation } from "@fedify/fedify/federation";
|
|
2
|
+
|
|
3
|
+
//#region src/mod.d.ts
|
|
4
|
+
|
|
5
|
+
interface HonoRequest {
|
|
6
|
+
raw: Request;
|
|
7
|
+
}
|
|
8
|
+
interface HonoContext {
|
|
9
|
+
req: HonoRequest;
|
|
10
|
+
res: Response;
|
|
11
|
+
}
|
|
12
|
+
type HonoMiddleware<THonoContext extends HonoContext> = (ctx: THonoContext, next: () => Promise<void>) => Promise<Response | void>;
|
|
13
|
+
/**
|
|
14
|
+
* A factory function to create a context data for the {@link Federation}
|
|
15
|
+
* object.
|
|
16
|
+
*
|
|
17
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
18
|
+
* object.
|
|
19
|
+
* @template THonoContext A type of the Hono context.
|
|
20
|
+
* @param context A Hono context object.
|
|
21
|
+
* @returns A context data for the {@link Federation} object.
|
|
22
|
+
* @since 1.9.0
|
|
23
|
+
*/
|
|
24
|
+
type ContextDataFactory<TContextData, THonoContext> = (context: THonoContext) => TContextData | Promise<TContextData>;
|
|
25
|
+
/**
|
|
26
|
+
* Create a Hono middleware to integrate with the {@link Federation} object.
|
|
27
|
+
*
|
|
28
|
+
* @template TContextData A type of the context data for the {@link Federation}
|
|
29
|
+
* object.
|
|
30
|
+
* @template THonoContext A type of the Hono context.
|
|
31
|
+
* @param federation A {@link Federation} object to integrate with Hono.
|
|
32
|
+
* @param contextDataFactory A function to create a context data for the
|
|
33
|
+
* {@link Federation} object.
|
|
34
|
+
* @returns A Hono middleware.
|
|
35
|
+
* @since 1.9.0
|
|
36
|
+
*/
|
|
37
|
+
declare function federation<TContextData, THonoContext extends HonoContext>(federation: Federation<TContextData>, contextDataFactory: ContextDataFactory<TContextData, THonoContext>): HonoMiddleware<THonoContext>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { ContextDataFactory, federation };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fedify/hono",
|
|
3
|
-
"version": "2.0.0-dev.
|
|
3
|
+
"version": "2.0.0-dev.159+6c07cd44",
|
|
4
4
|
"description": "Integrate Fedify with Hono",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Fedify",
|
|
@@ -28,21 +28,19 @@
|
|
|
28
28
|
"https://github.com/sponsors/dahlia"
|
|
29
29
|
],
|
|
30
30
|
"type": "module",
|
|
31
|
-
"main": "./dist/mod.
|
|
31
|
+
"main": "./dist/mod.cjs",
|
|
32
32
|
"module": "./dist/mod.js",
|
|
33
33
|
"types": "./dist/mod.d.ts",
|
|
34
34
|
"exports": {
|
|
35
35
|
".": {
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"default": "./dist/mod.
|
|
36
|
+
"types": {
|
|
37
|
+
"import": "./dist/mod.d.ts",
|
|
38
|
+
"require": "./dist/mod.d.cts",
|
|
39
|
+
"default": "./dist/mod.d.ts"
|
|
40
40
|
},
|
|
41
|
-
"import":
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"default": "./dist/mod.js"
|
|
45
|
-
}
|
|
41
|
+
"import": "./dist/mod.js",
|
|
42
|
+
"require": "./dist/mod.cjs",
|
|
43
|
+
"default": "./dist/mod.js"
|
|
46
44
|
},
|
|
47
45
|
"./package.json": "./package.json"
|
|
48
46
|
},
|
|
@@ -52,15 +50,15 @@
|
|
|
52
50
|
],
|
|
53
51
|
"peerDependencies": {
|
|
54
52
|
"hono": "^4.0.0",
|
|
55
|
-
"@fedify/fedify": "2.0.0-dev.
|
|
53
|
+
"@fedify/fedify": "^2.0.0-dev.159+6c07cd44"
|
|
56
54
|
},
|
|
57
55
|
"devDependencies": {
|
|
58
56
|
"tsdown": "^0.12.9",
|
|
59
|
-
"typescript": "^5.9.
|
|
57
|
+
"typescript": "^5.9.3"
|
|
60
58
|
},
|
|
61
59
|
"scripts": {
|
|
62
60
|
"build": "tsdown",
|
|
63
61
|
"prepublish": "tsdown",
|
|
64
|
-
"test": "
|
|
62
|
+
"test": "node --experimental-transform-types --test"
|
|
65
63
|
}
|
|
66
64
|
}
|