@hono/node-server 2.0.0-rc.1 → 2.0.0
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 +55 -11
- package/dist/{listener-Brd4yZ5d.js → index.cjs} +388 -108
- package/dist/{index.d.ts → index.d.cts} +12 -1
- package/dist/index.d.mts +12 -1
- package/dist/index.mjs +981 -4
- package/dist/{serve-static.js → serve-static.cjs} +1 -1
- package/dist/serve-static.mjs +1 -1
- package/dist/utils/{response.js → response.cjs} +1 -1
- package/dist/utils/response.mjs +1 -1
- package/package.json +44 -29
- package/dist/index.js +0 -28
- package/dist/listener-RIBxK9_x.mjs +0 -715
- package/dist/vercel.d.mts +0 -8
- package/dist/vercel.d.ts +0 -8
- package/dist/vercel.js +0 -10
- package/dist/vercel.mjs +0 -9
- /package/dist/{conninfo.js → conninfo.cjs} +0 -0
- /package/dist/{conninfo.d.ts → conninfo.d.cts} +0 -0
- /package/dist/{constants-DEKKqoym.mjs → constants-BLSFu_RU.mjs} +0 -0
- /package/dist/{constants-B7DBcQew.js → constants-BXAKTxRC.cjs} +0 -0
- /package/dist/{serve-static.d.ts → serve-static.d.cts} +0 -0
- /package/dist/utils/{response.d.ts → response.d.cts} +0 -0
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
# Node.js Adapter for Hono
|
|
2
2
|
|
|
3
3
|
This adapter `@hono/node-server` allows you to run your Hono application on Node.js.
|
|
4
|
-
Initially, Hono wasn't designed for Node.js, but with this adapter, you can now use Hono on Node.js.
|
|
5
|
-
It utilizes web standard APIs implemented in Node.js version 18 or higher.
|
|
4
|
+
Initially, Hono wasn't designed for Node.js, but with this adapter, you can now use Hono on Node.js. It utilizes web standard APIs implemented in Node.js.
|
|
6
5
|
|
|
7
6
|
## Benchmarks
|
|
8
7
|
|
|
9
|
-
Hono is
|
|
8
|
+
Hono is 4.1 times faster than Express.
|
|
10
9
|
|
|
11
10
|
Express:
|
|
12
11
|
|
|
@@ -14,12 +13,12 @@ Express:
|
|
|
14
13
|
$ bombardier -d 10s --fasthttp http://localhost:3000/
|
|
15
14
|
|
|
16
15
|
Statistics Avg Stdev Max
|
|
17
|
-
Reqs/sec
|
|
18
|
-
Latency
|
|
16
|
+
Reqs/sec 20803.37 1713.06 24910.85
|
|
17
|
+
Latency 6.01ms 5.21ms 451.37ms
|
|
19
18
|
HTTP codes:
|
|
20
|
-
1xx - 0, 2xx -
|
|
19
|
+
1xx - 0, 2xx - 208131, 3xx - 0, 4xx - 0, 5xx - 0
|
|
21
20
|
others - 0
|
|
22
|
-
Throughput:
|
|
21
|
+
Throughput: 5.75MB/s
|
|
23
22
|
```
|
|
24
23
|
|
|
25
24
|
Hono + `@hono/node-server`:
|
|
@@ -28,12 +27,12 @@ Hono + `@hono/node-server`:
|
|
|
28
27
|
$ bombardier -d 10s --fasthttp http://localhost:3000/
|
|
29
28
|
|
|
30
29
|
Statistics Avg Stdev Max
|
|
31
|
-
Reqs/sec
|
|
32
|
-
Latency
|
|
30
|
+
Reqs/sec 85405.51 7250.65 102658.51
|
|
31
|
+
Latency 1.46ms 1.00ms 149.95ms
|
|
33
32
|
HTTP codes:
|
|
34
|
-
1xx - 0, 2xx -
|
|
33
|
+
1xx - 0, 2xx - 854120, 3xx - 0, 4xx - 0, 5xx - 0
|
|
35
34
|
others - 0
|
|
36
|
-
Throughput:
|
|
35
|
+
Throughput: 18.49MB/s
|
|
37
36
|
```
|
|
38
37
|
|
|
39
38
|
## Requirements
|
|
@@ -71,6 +70,34 @@ serve(app, (info) => {
|
|
|
71
70
|
})
|
|
72
71
|
```
|
|
73
72
|
|
|
73
|
+
## WebSocket
|
|
74
|
+
|
|
75
|
+
You can upgrade WebSocket connections with `upgradeWebSocket` from `@hono/node-server`.
|
|
76
|
+
To enable this, install `ws` (and `@types/ws`) in your project, then create and provide a `WebSocketServer` as shown in the example below.
|
|
77
|
+
|
|
78
|
+
```ts
|
|
79
|
+
import { serve, upgradeWebSocket } from '@hono/node-server'
|
|
80
|
+
import { WebSocketServer } from 'ws'
|
|
81
|
+
import { Hono } from 'hono'
|
|
82
|
+
|
|
83
|
+
const app = new Hono()
|
|
84
|
+
|
|
85
|
+
app.get(
|
|
86
|
+
'/ws',
|
|
87
|
+
upgradeWebSocket(() => ({
|
|
88
|
+
onMessage(event, ws) {
|
|
89
|
+
ws.send(event.data)
|
|
90
|
+
},
|
|
91
|
+
}))
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
const wss = new WebSocketServer({ noServer: true }) // important to create with `noServer: true`
|
|
95
|
+
serve({
|
|
96
|
+
fetch: app.fetch,
|
|
97
|
+
websocket: { server: wss },
|
|
98
|
+
})
|
|
99
|
+
```
|
|
100
|
+
|
|
74
101
|
For example, run it using `ts-node`. Then an HTTP server will be launched. The default port is `3000`.
|
|
75
102
|
|
|
76
103
|
```sh
|
|
@@ -132,6 +159,23 @@ serve({
|
|
|
132
159
|
})
|
|
133
160
|
```
|
|
134
161
|
|
|
162
|
+
### `websocket`
|
|
163
|
+
|
|
164
|
+
provide a websocket server to enable websocket support.
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
import { serve, upgradeWebSocket } from '@hono/node-server'
|
|
168
|
+
import { WebSocketServer } from 'ws'
|
|
169
|
+
|
|
170
|
+
// ...
|
|
171
|
+
const wss = new WebSocketServer({ noServer: true })
|
|
172
|
+
|
|
173
|
+
serve({
|
|
174
|
+
fetch: app.fetch,
|
|
175
|
+
websocket: { server: wss },
|
|
176
|
+
})
|
|
177
|
+
```
|
|
178
|
+
|
|
135
179
|
## Middleware
|
|
136
180
|
|
|
137
181
|
Most built-in middleware also works with Node.js.
|