@hono/node-server 1.19.14 → 2.0.0-rc.2
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 +56 -18
- package/dist/conninfo.cjs +22 -0
- package/dist/{conninfo.d.ts → conninfo.d.cts} +4 -3
- package/dist/conninfo.d.mts +4 -3
- package/dist/conninfo.mjs +19 -16
- package/dist/constants-BLSFu_RU.mjs +5 -0
- package/dist/constants-BXAKTxRC.cjs +11 -0
- package/dist/index.cjs +1006 -0
- package/dist/index.d.cts +73 -0
- package/dist/index.d.mts +73 -8
- package/dist/index.mjs +976 -637
- package/dist/serve-static.cjs +135 -0
- package/dist/serve-static.d.cts +18 -0
- package/dist/serve-static.d.mts +14 -13
- package/dist/serve-static.mjs +127 -145
- package/dist/utils/response.cjs +8 -0
- package/dist/utils/response.d.cts +4 -0
- package/dist/utils/response.d.mts +3 -2
- package/dist/utils/response.mjs +6 -9
- package/package.json +53 -40
- package/dist/conninfo.js +0 -42
- package/dist/globals.d.mts +0 -2
- package/dist/globals.d.ts +0 -2
- package/dist/globals.js +0 -29
- package/dist/globals.mjs +0 -5
- package/dist/index.d.ts +0 -8
- package/dist/index.js +0 -702
- package/dist/listener.d.mts +0 -13
- package/dist/listener.d.ts +0 -13
- package/dist/listener.js +0 -670
- package/dist/listener.mjs +0 -635
- package/dist/request.d.mts +0 -25
- package/dist/request.d.ts +0 -25
- package/dist/request.js +0 -238
- package/dist/request.mjs +0 -206
- package/dist/response.d.mts +0 -26
- package/dist/response.d.ts +0 -26
- package/dist/response.js +0 -112
- package/dist/response.mjs +0 -85
- package/dist/serve-static.d.ts +0 -17
- package/dist/serve-static.js +0 -177
- package/dist/server.d.mts +0 -10
- package/dist/server.d.ts +0 -10
- package/dist/server.js +0 -696
- package/dist/server.mjs +0 -660
- package/dist/types.d.mts +0 -44
- package/dist/types.d.ts +0 -44
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -0
- package/dist/utils/response/constants.d.mts +0 -3
- package/dist/utils/response/constants.d.ts +0 -3
- package/dist/utils/response/constants.js +0 -30
- package/dist/utils/response/constants.mjs +0 -5
- package/dist/utils/response.d.ts +0 -3
- package/dist/utils/response.js +0 -37
- package/dist/utils.d.mts +0 -9
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +0 -99
- package/dist/utils.mjs +0 -71
- package/dist/vercel.d.mts +0 -7
- package/dist/vercel.d.ts +0 -7
- package/dist/vercel.js +0 -677
- package/dist/vercel.mjs +0 -640
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,23 +27,17 @@ 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
|
|
40
39
|
|
|
41
|
-
It works on Node.js versions greater than
|
|
42
|
-
|
|
43
|
-
- 18.x => 18.14.1+
|
|
44
|
-
- 19.x => 19.7.0+
|
|
45
|
-
- 20.x => 20.0.0+
|
|
46
|
-
|
|
47
|
-
Essentially, you can simply use the latest version of each major release.
|
|
40
|
+
It works on Node.js versions greater than 20.x.
|
|
48
41
|
|
|
49
42
|
## Installation
|
|
50
43
|
|
|
@@ -77,6 +70,34 @@ serve(app, (info) => {
|
|
|
77
70
|
})
|
|
78
71
|
```
|
|
79
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
|
+
|
|
80
101
|
For example, run it using `ts-node`. Then an HTTP server will be launched. The default port is `3000`.
|
|
81
102
|
|
|
82
103
|
```sh
|
|
@@ -138,6 +159,23 @@ serve({
|
|
|
138
159
|
})
|
|
139
160
|
```
|
|
140
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
|
+
|
|
141
179
|
## Middleware
|
|
142
180
|
|
|
143
181
|
Most built-in middleware also works with Node.js.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
|
|
3
|
+
//#region src/conninfo.ts
|
|
4
|
+
/**
|
|
5
|
+
* ConnInfo Helper for Node.js
|
|
6
|
+
* @param c Context
|
|
7
|
+
* @returns ConnInfo
|
|
8
|
+
*/
|
|
9
|
+
const getConnInfo = (c) => {
|
|
10
|
+
const bindings = c.env.server ? c.env.server : c.env;
|
|
11
|
+
const address = bindings.incoming.socket.remoteAddress;
|
|
12
|
+
const port = bindings.incoming.socket.remotePort;
|
|
13
|
+
const family = bindings.incoming.socket.remoteFamily;
|
|
14
|
+
return { remote: {
|
|
15
|
+
address,
|
|
16
|
+
port,
|
|
17
|
+
addressType: family === "IPv4" ? "IPv4" : family === "IPv6" ? "IPv6" : void 0
|
|
18
|
+
} };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
exports.getConnInfo = getConnInfo;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { GetConnInfo } from
|
|
1
|
+
import { GetConnInfo } from "hono/conninfo";
|
|
2
2
|
|
|
3
|
+
//#region src/conninfo.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* ConnInfo Helper for Node.js
|
|
5
6
|
* @param c Context
|
|
6
7
|
* @returns ConnInfo
|
|
7
8
|
*/
|
|
8
9
|
declare const getConnInfo: GetConnInfo;
|
|
9
|
-
|
|
10
|
-
export { getConnInfo };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getConnInfo };
|
package/dist/conninfo.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { GetConnInfo } from
|
|
1
|
+
import { GetConnInfo } from "hono/conninfo";
|
|
2
2
|
|
|
3
|
+
//#region src/conninfo.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* ConnInfo Helper for Node.js
|
|
5
6
|
* @param c Context
|
|
6
7
|
* @returns ConnInfo
|
|
7
8
|
*/
|
|
8
9
|
declare const getConnInfo: GetConnInfo;
|
|
9
|
-
|
|
10
|
-
export { getConnInfo };
|
|
10
|
+
//#endregion
|
|
11
|
+
export { getConnInfo };
|
package/dist/conninfo.mjs
CHANGED
|
@@ -1,17 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
//#region src/conninfo.ts
|
|
2
|
+
/**
|
|
3
|
+
* ConnInfo Helper for Node.js
|
|
4
|
+
* @param c Context
|
|
5
|
+
* @returns ConnInfo
|
|
6
|
+
*/
|
|
7
|
+
const getConnInfo = (c) => {
|
|
8
|
+
const bindings = c.env.server ? c.env.server : c.env;
|
|
9
|
+
const address = bindings.incoming.socket.remoteAddress;
|
|
10
|
+
const port = bindings.incoming.socket.remotePort;
|
|
11
|
+
const family = bindings.incoming.socket.remoteFamily;
|
|
12
|
+
return { remote: {
|
|
13
|
+
address,
|
|
14
|
+
port,
|
|
15
|
+
addressType: family === "IPv4" ? "IPv4" : family === "IPv6" ? "IPv6" : void 0
|
|
16
|
+
} };
|
|
17
17
|
};
|
|
18
|
+
|
|
19
|
+
//#endregion
|
|
20
|
+
export { getConnInfo };
|