@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.
Files changed (63) hide show
  1. package/README.md +56 -18
  2. package/dist/conninfo.cjs +22 -0
  3. package/dist/{conninfo.d.ts → conninfo.d.cts} +4 -3
  4. package/dist/conninfo.d.mts +4 -3
  5. package/dist/conninfo.mjs +19 -16
  6. package/dist/constants-BLSFu_RU.mjs +5 -0
  7. package/dist/constants-BXAKTxRC.cjs +11 -0
  8. package/dist/index.cjs +1006 -0
  9. package/dist/index.d.cts +73 -0
  10. package/dist/index.d.mts +73 -8
  11. package/dist/index.mjs +976 -637
  12. package/dist/serve-static.cjs +135 -0
  13. package/dist/serve-static.d.cts +18 -0
  14. package/dist/serve-static.d.mts +14 -13
  15. package/dist/serve-static.mjs +127 -145
  16. package/dist/utils/response.cjs +8 -0
  17. package/dist/utils/response.d.cts +4 -0
  18. package/dist/utils/response.d.mts +3 -2
  19. package/dist/utils/response.mjs +6 -9
  20. package/package.json +53 -40
  21. package/dist/conninfo.js +0 -42
  22. package/dist/globals.d.mts +0 -2
  23. package/dist/globals.d.ts +0 -2
  24. package/dist/globals.js +0 -29
  25. package/dist/globals.mjs +0 -5
  26. package/dist/index.d.ts +0 -8
  27. package/dist/index.js +0 -702
  28. package/dist/listener.d.mts +0 -13
  29. package/dist/listener.d.ts +0 -13
  30. package/dist/listener.js +0 -670
  31. package/dist/listener.mjs +0 -635
  32. package/dist/request.d.mts +0 -25
  33. package/dist/request.d.ts +0 -25
  34. package/dist/request.js +0 -238
  35. package/dist/request.mjs +0 -206
  36. package/dist/response.d.mts +0 -26
  37. package/dist/response.d.ts +0 -26
  38. package/dist/response.js +0 -112
  39. package/dist/response.mjs +0 -85
  40. package/dist/serve-static.d.ts +0 -17
  41. package/dist/serve-static.js +0 -177
  42. package/dist/server.d.mts +0 -10
  43. package/dist/server.d.ts +0 -10
  44. package/dist/server.js +0 -696
  45. package/dist/server.mjs +0 -660
  46. package/dist/types.d.mts +0 -44
  47. package/dist/types.d.ts +0 -44
  48. package/dist/types.js +0 -18
  49. package/dist/types.mjs +0 -0
  50. package/dist/utils/response/constants.d.mts +0 -3
  51. package/dist/utils/response/constants.d.ts +0 -3
  52. package/dist/utils/response/constants.js +0 -30
  53. package/dist/utils/response/constants.mjs +0 -5
  54. package/dist/utils/response.d.ts +0 -3
  55. package/dist/utils/response.js +0 -37
  56. package/dist/utils.d.mts +0 -9
  57. package/dist/utils.d.ts +0 -9
  58. package/dist/utils.js +0 -99
  59. package/dist/utils.mjs +0 -71
  60. package/dist/vercel.d.mts +0 -7
  61. package/dist/vercel.d.ts +0 -7
  62. package/dist/vercel.js +0 -677
  63. 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 3.5 times faster than Express.
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 16438.94 1603.39 19155.47
18
- Latency 7.60ms 7.51ms 559.89ms
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 - 164494, 3xx - 0, 4xx - 0, 5xx - 0
19
+ 1xx - 0, 2xx - 208131, 3xx - 0, 4xx - 0, 5xx - 0
21
20
  others - 0
22
- Throughput: 4.55MB/s
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 58296.56 5512.74 74403.56
32
- Latency 2.14ms 1.46ms 190.92ms
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 - 583059, 3xx - 0, 4xx - 0, 5xx - 0
33
+ 1xx - 0, 2xx - 854120, 3xx - 0, 4xx - 0, 5xx - 0
35
34
  others - 0
36
- Throughput: 12.56MB/s
35
+ Throughput: 18.49MB/s
37
36
  ```
38
37
 
39
38
  ## Requirements
40
39
 
41
- It works on Node.js versions greater than 18.x. The specific required Node.js versions are as follows:
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 'hono/conninfo';
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 };
@@ -1,10 +1,11 @@
1
- import { GetConnInfo } from 'hono/conninfo';
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
- // src/conninfo.ts
2
- var getConnInfo = (c) => {
3
- const bindings = c.env.server ? c.env.server : c.env;
4
- const address = bindings.incoming.socket.remoteAddress;
5
- const port = bindings.incoming.socket.remotePort;
6
- const family = bindings.incoming.socket.remoteFamily;
7
- return {
8
- remote: {
9
- address,
10
- port,
11
- addressType: family === "IPv4" ? "IPv4" : family === "IPv6" ? "IPv6" : void 0
12
- }
13
- };
14
- };
15
- export {
16
- getConnInfo
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 };
@@ -0,0 +1,5 @@
1
+ //#region src/utils/response/constants.ts
2
+ const X_ALREADY_SENT = "x-hono-already-sent";
3
+
4
+ //#endregion
5
+ export { X_ALREADY_SENT as t };
@@ -0,0 +1,11 @@
1
+
2
+ //#region src/utils/response/constants.ts
3
+ const X_ALREADY_SENT = "x-hono-already-sent";
4
+
5
+ //#endregion
6
+ Object.defineProperty(exports, 'X_ALREADY_SENT', {
7
+ enumerable: true,
8
+ get: function () {
9
+ return X_ALREADY_SENT;
10
+ }
11
+ });