@hono/node-server 0.5.1 → 0.6.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 +23 -5
- package/dist/server.d.ts +2 -1
- package/dist/server.js +7 -3
- package/dist/types.d.ts +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
# Hono on Node.js
|
|
2
2
|
|
|
3
|
-
**`@honojs/node-server` is renamed to `@hono/node-server` !!**
|
|
4
|
-
|
|
5
|
-
---
|
|
6
|
-
|
|
7
3
|
This is **HTTP Server for Hono on Node.js**.
|
|
8
4
|
Hono is ultrafast web framework for Cloudflare Workers, Deno, and Bun.
|
|
9
5
|
**It's not for Node.js**.
|
|
@@ -39,7 +35,9 @@ import { Hono } from 'hono'
|
|
|
39
35
|
const app = new Hono()
|
|
40
36
|
app.get('/', (c) => c.text('Hono meets Node.js'))
|
|
41
37
|
|
|
42
|
-
serve(app)
|
|
38
|
+
serve(app, (info) => {
|
|
39
|
+
console.log(`Listening on http://localhost:${info.port}`) // Listening on http://localhost:3000
|
|
40
|
+
})
|
|
43
41
|
```
|
|
44
42
|
|
|
45
43
|
For example, run it using `ts-node`. Then an HTTP server will be launched. The default port is `3000`.
|
|
@@ -52,6 +50,8 @@ Open `http://localhost:3000` with your browser.
|
|
|
52
50
|
|
|
53
51
|
## Options
|
|
54
52
|
|
|
53
|
+
### `port`
|
|
54
|
+
|
|
55
55
|
```ts
|
|
56
56
|
serve({
|
|
57
57
|
fetch: app.fetch,
|
|
@@ -59,6 +59,24 @@ serve({
|
|
|
59
59
|
})
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
+
### `createServer`
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { createServer } from 'node:https'
|
|
66
|
+
import fs from 'node:fs'
|
|
67
|
+
|
|
68
|
+
//...
|
|
69
|
+
|
|
70
|
+
serve({
|
|
71
|
+
fetch: app.fetch,
|
|
72
|
+
createServer: createServer,
|
|
73
|
+
serverOptions: {
|
|
74
|
+
key: fs.readFileSync('test/fixtures/keys/agent1-key.pem'),
|
|
75
|
+
cert: fs.readFileSync('test/fixtures/keys/agent1-cert.pem'),
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
```
|
|
79
|
+
|
|
62
80
|
## Middleware
|
|
63
81
|
|
|
64
82
|
Most built-in middleware also works with Node.js.
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Server } from 'node:http';
|
|
2
2
|
import { Options } from './types';
|
|
3
|
+
import type { AddressInfo } from 'node:net';
|
|
3
4
|
export declare const createAdaptorServer: (options: Options) => Server;
|
|
4
|
-
export declare const serve: (options: Options) => Server;
|
|
5
|
+
export declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => Server;
|
package/dist/server.js
CHANGED
|
@@ -8,13 +8,17 @@ const listener_1 = require("./listener");
|
|
|
8
8
|
const createAdaptorServer = (options) => {
|
|
9
9
|
const fetchCallback = options.fetch;
|
|
10
10
|
const requestListener = (0, listener_1.getRequestListener)(fetchCallback);
|
|
11
|
-
const
|
|
11
|
+
const createServer = options.createServer || node_http_1.createServer;
|
|
12
|
+
const server = createServer(options.serverOptions || {}, requestListener);
|
|
12
13
|
return server;
|
|
13
14
|
};
|
|
14
15
|
exports.createAdaptorServer = createAdaptorServer;
|
|
15
|
-
const serve = (options) => {
|
|
16
|
+
const serve = (options, listeningListener) => {
|
|
16
17
|
const server = (0, exports.createAdaptorServer)(options);
|
|
17
|
-
server.listen(options
|
|
18
|
+
server.listen(options?.port ?? 3000, options.hostname ?? '0.0.0.0', () => {
|
|
19
|
+
const serverInfo = server.address();
|
|
20
|
+
listeningListener && listeningListener(serverInfo);
|
|
21
|
+
});
|
|
18
22
|
return server;
|
|
19
23
|
};
|
|
20
24
|
exports.serve = serve;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type { Hono } from 'hono';
|
|
2
3
|
import type { NextApiHandler } from 'next/types';
|
|
4
|
+
import type { createServer } from 'node:http';
|
|
3
5
|
export declare type FetchCallback = (request: Request) => Promise<unknown> | unknown;
|
|
4
6
|
export declare type NextHandlerOption = {
|
|
5
7
|
fetch: FetchCallback;
|
|
@@ -9,6 +11,7 @@ export declare type Options = {
|
|
|
9
11
|
port?: number;
|
|
10
12
|
hostname?: string;
|
|
11
13
|
serverOptions?: Object;
|
|
14
|
+
createServer?: typeof createServer;
|
|
12
15
|
};
|
|
13
16
|
export interface HandleInterface {
|
|
14
17
|
<E extends Hono<any, any>>(subApp: E, path?: string): NextApiHandler;
|