@dotpress/adapter-hono 2.0.0-alpha.2 → 2.0.0-alpha.3

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.
Files changed (2) hide show
  1. package/README.md +8 -54
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,13 +1,11 @@
1
1
  # @dotpress/adapter-hono
2
2
 
3
- [Hono](https://hono.dev) adapter for [Dotpress](https://dotpress.dev), on Node.js and AWS Lambda. Supports Hono 4 (4.13 or later); Hono 5 is tested against its release candidate.
3
+ [Hono](https://hono.dev) adapter for [Dotpress](https://dotpress.dev), on Node.js and AWS Lambda. Supports Hono 4.13 or later; Hono 5 is tested against its release candidate.
4
4
 
5
5
  > 🚧 Dotpress V2 is in alpha (`2.0.0-alpha`): the API may still change before 2.0.0.
6
6
 
7
- ## On Node.js
8
-
9
7
  ```sh
10
- pnpm add @dotpress/core @dotpress/adapter-hono hono @hono/node-server zod
8
+ npm install @dotpress/core @dotpress/adapter-hono hono @hono/node-server zod
11
9
  ```
12
10
 
13
11
  ```ts
@@ -29,64 +27,20 @@ const app = await createApp({
29
27
  await app.listen(3000)
30
28
  ```
31
29
 
32
- `@dotpress/adapter-hono/node` serves the app with [`@hono/node-server`](https://github.com/honojs/node-server). `close()` waits for pending requests and closes the responses being streamed (Server-Sent Events); `adapter.server()` returns the Node.js HTTP server started by `listen()`.
33
-
34
- ## On AWS Lambda
35
-
36
- ```sh
37
- pnpm add @dotpress/core @dotpress/adapter-hono hono @hono/aws-lambda zod
38
- ```
30
+ On AWS Lambda, with `@hono/aws-lambda` and the main entry, which has no Node.js server:
39
31
 
40
32
  ```ts
41
- import { createApp } from '@dotpress/core'
42
33
  import { honoAdapter } from '@dotpress/adapter-hono'
43
34
  import { createLambdaHandler } from '@dotpress/adapter-hono/lambda'
44
35
 
45
- export const handler = createLambdaHandler(() =>
46
- createApp({ adapter: honoAdapter(), plugins: [/* ... */] })
47
- )
48
- ```
49
-
50
- `createLambdaHandler()` (based on [`@hono/aws-lambda`](https://github.com/honojs/middleware), which requires Hono 4.13.9 or later) handles the events of API Gateway REST APIs (payload v1), HTTP APIs and Function URLs (payload v2), and Application Load Balancers. Enable the multi-value headers of the target group to receive repeated query keys and send several cookies through a load balancer.
51
-
52
- - **Lazy creation.** The factory is called at the first invocation (cold start), and the app is reused by the next invocations of the execution environment. Invocations received meanwhile wait for the same app. The handler export stays synchronous: no top-level `await`.
53
- - **Recoverable failures.** When the factory fails, the error is logged (`logger` option, console by default), the invocation gets the standard `500` error, and the next invocation calls the factory again.
54
- - **Buffered responses.** Responses are sent once complete: `stream()` works for finite streams, but Server-Sent Events (`sse()`) are not supported, and a stream that fails makes the invocation fail (`502` from API Gateway) rather than sending a truncated response. Lambda response streaming is not supported yet.
55
- - **Binary responses** are sent in base64: every content type except text, JSON and XML by default, or as decided by the `isContentTypeBinary(contentType)` option.
56
- - **`ctx.req.ip`** is the source IP of API Gateway, or the last `X-Forwarded-For` entry behind a load balancer (appended by the load balancer). Behind CloudFront or another proxy, use the `getIp(c)` option of `honoAdapter()`.
57
-
58
- ## Other runtimes
59
-
60
- The main entry, `@dotpress/adapter-hono`, only relies on Hono and Web-standard APIs: no Node.js server. `adapter.fetch` handles a Web `Request`, like `app.fetch` in Hono, for runtimes that take a `fetch` handler:
61
-
62
- ```ts
63
- import { honoAdapter } from '@dotpress/adapter-hono'
64
-
65
- const adapter = honoAdapter()
66
- await createApp({ adapter })
67
-
68
- export default { fetch: adapter.fetch }
36
+ export const handler = createLambdaHandler(() => createApp({ adapter: honoAdapter() }))
69
37
  ```
70
38
 
71
- Outside Node.js, `ctx.req.ip` comes from the `getIp(c)` option. Dotpress V2.0 is only tested on Node.js: other runtimes are not officially supported yet.
72
-
73
- ## Options
74
-
75
- | Option | Description |
76
- | --- | --- |
77
- | `app` | Existing Hono application. Defaults to `new Hono()`. |
78
- | `beforeRoutes(app)` | Registers native middlewares and routes before the Dotpress routes. |
79
- | `afterRoutes(app)` | Registers native middlewares and routes after the Dotpress routes, before the not-found handler. |
80
- | `bodyLimit` | Maximum request body size in bytes. Defaults to 1 MiB. |
81
- | `getIp(c)` | Client IP address (`ctx.req.ip`). Defaults to the address given by the runtime: the socket address on Node.js, see below for AWS Lambda. |
82
-
83
- ## Behavior
39
+ ## Documentation
84
40
 
85
- - Routes are matched by Dotpress, so they behave the same on every adapter (case-sensitive, static segments before parameters, Hono options such as `strict` do not apply). Use the `basePath` option of `createApp()` rather than `app.basePath()`.
86
- - Request bodies are read by the adapter: JSON, URL-encoded forms, text and multipart forms are parsed, other content types are exposed as `Uint8Array`. Bodies already read by a native middleware through Hono (`c.req.json()`, `c.req.parseBody()`…) are taken from its cache. Routes declared with `rawBody: true` need the exact bytes: the adapter must read the body, or a native middleware must read it with `c.req.arrayBuffer()` or `c.req.blob()`.
87
- - `HTTPException` client errors (4xx) thrown by native middlewares use the Dotpress error format and keep their status, message and headers (`WWW-Authenticate` of `bearerAuth()`…). Other errors are unexpected errors (`500`). The adapter takes over `app.notFound()` and `app.onError()`.
88
- - `ctx.req.ip` does not read proxy headers such as `X-Forwarded-For`: behind a proxy, read them in `getIp(c)`.
89
- - `ctx.raw` is the Hono context.
41
+ - [The Hono adapter](https://dotpress.dev/adapters/hono): options, native middlewares, bodies, errors, other runtimes
42
+ - [The AWS Lambda adapter](https://dotpress.dev/adapters/aws-lambda)
43
+ - [Choosing an adapter](https://dotpress.dev/adapters/)
90
44
 
91
45
  ## License
92
46
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dotpress/adapter-hono",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.3",
4
4
  "description": "Hono adapter for Dotpress, on Node.js and AWS Lambda",
5
5
  "author": "Renaud Guyon",
6
6
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "node": ">=22.12"
39
39
  },
40
40
  "peerDependencies": {
41
- "@dotpress/core": "^2.0.0-alpha.2",
41
+ "@dotpress/core": "^2.0.0-alpha.3",
42
42
  "@hono/aws-lambda": "^1.0.0",
43
43
  "@hono/node-server": "^2.1.0",
44
44
  "hono": "^4.13.0"
@@ -52,8 +52,8 @@
52
52
  }
53
53
  },
54
54
  "devDependencies": {
55
- "@dotpress/core": "2.0.0-alpha.2",
56
- "@dotpress/testing": "2.0.0-alpha.2",
55
+ "@dotpress/core": "2.0.0-alpha.3",
56
+ "@dotpress/testing": "2.0.0-alpha.3",
57
57
  "@hono/aws-lambda": "^1.0.1",
58
58
  "@hono/node-server": "^2.1.6",
59
59
  "hono": "^4.13.17",