react-router-hono-server 2.26.0 → 3.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 +1 -1
- package/dist/adapters/aws-lambda.d.ts +17 -70
- package/dist/adapters/aws-lambda.js +73 -71
- package/dist/adapters/bun.d.ts +37 -40
- package/dist/adapters/bun.js +114 -131
- package/dist/adapters/cloudflare.d.ts +8 -12
- package/dist/adapters/cloudflare.js +84 -98
- package/dist/adapters/deno.d.ts +33 -35
- package/dist/adapters/deno.js +100 -104
- package/dist/adapters/node.d.ts +62 -67
- package/dist/adapters/node.js +94 -103
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +32 -39
- package/dist/dev.d.ts +45 -43
- package/dist/dev.js +182 -284
- package/dist/{helpers-BXdVojwF.d.ts → helpers-CvvzWAWX.d.ts} +20 -24
- package/dist/helpers-DpeZU9Bf.js +108 -0
- package/dist/http.d.ts +4 -3
- package/dist/http.js +53 -48
- package/dist/middleware.d.ts +4 -5
- package/dist/middleware.js +17 -6
- package/package.json +29 -29
- package/dist/chunk-BH64OQMW.js +0 -102
- package/dist/chunk-YI5FED4X.js +0 -18
|
@@ -1,106 +1,92 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
createGetLoadContext,
|
|
4
|
-
getBuildMode,
|
|
5
|
-
importBuild
|
|
6
|
-
} from "../chunk-BH64OQMW.js";
|
|
7
|
-
import {
|
|
8
|
-
cache
|
|
9
|
-
} from "../chunk-YI5FED4X.js";
|
|
10
|
-
|
|
11
|
-
// src/adapters/cloudflare.ts
|
|
1
|
+
import { a as getBuildMode, o as importBuild, r as createGetLoadContext, t as bindIncomingRequestSocketInfo } from "../helpers-DpeZU9Bf.js";
|
|
2
|
+
import { cache } from "../middleware.js";
|
|
12
3
|
import { Hono } from "hono";
|
|
13
4
|
import { createMiddleware } from "hono/factory";
|
|
14
5
|
import { logger } from "hono/logger";
|
|
15
6
|
import { createRequestHandler } from "react-router";
|
|
7
|
+
//#region src/adapters/cloudflare.ts
|
|
8
|
+
/**
|
|
9
|
+
* Create a Hono server
|
|
10
|
+
*
|
|
11
|
+
* @param config {@link HonoServerOptions} - The configuration options for the server
|
|
12
|
+
*/
|
|
16
13
|
async function createHonoServer(options) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
if (!PRODUCTION) {
|
|
71
|
-
console.log("\u{1F6A7} Running in development mode");
|
|
72
|
-
}
|
|
73
|
-
return app;
|
|
14
|
+
const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
|
|
15
|
+
const mergedOptions = {
|
|
16
|
+
...options,
|
|
17
|
+
defaultLogger: options?.defaultLogger ?? true
|
|
18
|
+
};
|
|
19
|
+
const mode = getBuildMode();
|
|
20
|
+
const PRODUCTION = mode === "production";
|
|
21
|
+
const app = new Hono(mergedOptions.app);
|
|
22
|
+
/**
|
|
23
|
+
* Add optional middleware that runs before any built-in middleware, including assets serving.
|
|
24
|
+
*/
|
|
25
|
+
await mergedOptions.beforeAll?.(app);
|
|
26
|
+
/**
|
|
27
|
+
* Serve assets files from build/client/assets
|
|
28
|
+
*/
|
|
29
|
+
app.use(`/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`, cache(3600 * 24 * 365), serveCloudflareAssets());
|
|
30
|
+
/**
|
|
31
|
+
* Serve public files
|
|
32
|
+
*/
|
|
33
|
+
if (PRODUCTION) app.use("*", cache(3600), serveCloudflareAssets());
|
|
34
|
+
else {
|
|
35
|
+
const { serveStatic } = await import("@hono/node-server/serve-static");
|
|
36
|
+
app.use("*", cache(3600), serveStatic({ root: "./public" }));
|
|
37
|
+
app.use(bindIncomingRequestSocketInfo());
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Add logger middleware
|
|
41
|
+
*/
|
|
42
|
+
if (mergedOptions.defaultLogger) app.use("*", logger());
|
|
43
|
+
/**
|
|
44
|
+
* Add optional middleware
|
|
45
|
+
*/
|
|
46
|
+
await mergedOptions.configure?.(app);
|
|
47
|
+
/**
|
|
48
|
+
* Create a React Router Hono app and bind it to the root Hono server using the React Router basename
|
|
49
|
+
*/
|
|
50
|
+
const reactRouterApp = new Hono({ strict: false });
|
|
51
|
+
reactRouterApp.use(async (c, next) => {
|
|
52
|
+
const build = await importBuild();
|
|
53
|
+
return createMiddleware(async (c) => {
|
|
54
|
+
const requestHandler = createRequestHandler(build, mode);
|
|
55
|
+
const loadContext = mergedOptions.getLoadContext?.(c, {
|
|
56
|
+
build,
|
|
57
|
+
mode
|
|
58
|
+
});
|
|
59
|
+
return requestHandler(c.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
|
|
60
|
+
})(c, next);
|
|
61
|
+
});
|
|
62
|
+
app.route(`${basename}`, reactRouterApp);
|
|
63
|
+
if (basename) app.route(`${basename}.data`, reactRouterApp);
|
|
64
|
+
if (!PRODUCTION) console.log("🚧 Running in development mode");
|
|
65
|
+
return app;
|
|
74
66
|
}
|
|
75
|
-
|
|
67
|
+
let warned = false;
|
|
68
|
+
/**
|
|
69
|
+
* Serve static assets
|
|
70
|
+
*
|
|
71
|
+
* https://github.com/sergiodxa/remix-hono/blob/main/src/cloudflare.ts
|
|
72
|
+
*/
|
|
76
73
|
function serveCloudflareAssets() {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
if (response.status >= 400) {
|
|
94
|
-
return next();
|
|
95
|
-
}
|
|
96
|
-
response = new Response(response.body, response);
|
|
97
|
-
return response;
|
|
98
|
-
} catch {
|
|
99
|
-
return next();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
74
|
+
return createMiddleware(async (c, next) => {
|
|
75
|
+
const binding = c.env?.ASSETS;
|
|
76
|
+
if (!binding) {
|
|
77
|
+
if (!warned) console.info("\x1B[33m\nThe binding ASSETS is not set. Falling back to Cloudflare serving.\nhttps://developers.cloudflare.com/workers/static-assets/binding/#binding\n\x1B[0m");
|
|
78
|
+
warned = true;
|
|
79
|
+
return next();
|
|
80
|
+
}
|
|
81
|
+
try {
|
|
82
|
+
let response = await binding.fetch(c.req.url, c.req.raw.clone());
|
|
83
|
+
if (response.status >= 400) return next();
|
|
84
|
+
response = new Response(response.body, response);
|
|
85
|
+
return response;
|
|
86
|
+
} catch {
|
|
87
|
+
return next();
|
|
88
|
+
}
|
|
89
|
+
});
|
|
102
90
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
createHonoServer
|
|
106
|
-
};
|
|
91
|
+
//#endregion
|
|
92
|
+
export { createGetLoadContext, createHonoServer };
|
package/dist/adapters/deno.d.ts
CHANGED
|
@@ -1,45 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { BlankEnv } from
|
|
4
|
-
import {
|
|
5
|
-
export { c as createGetLoadContext } from '../helpers-BXdVojwF.js';
|
|
6
|
-
import 'hono/ws';
|
|
7
|
-
import 'react-router';
|
|
1
|
+
import { i as WithoutWebsocket, n as HonoServerOptionsBase, t as createGetLoadContext } from "../helpers-CvvzWAWX.js";
|
|
2
|
+
import { Env, Hono } from "hono";
|
|
3
|
+
import { BlankEnv } from "hono/types";
|
|
4
|
+
import { ServeStaticOptions } from "hono/serve-static";
|
|
8
5
|
|
|
6
|
+
//#region src/adapters/deno.d.ts
|
|
9
7
|
type CustomDenoServer = Deno.ServeTcpOptions;
|
|
10
8
|
interface HonoDenoServerOptions<E extends Env = BlankEnv> extends HonoServerOptionsBase<E> {
|
|
9
|
+
/**
|
|
10
|
+
* Customize the deno server
|
|
11
|
+
*
|
|
12
|
+
* {@link https://docs.deno.com/api/deno/~/Deno.serve#parameters}
|
|
13
|
+
*/
|
|
14
|
+
customDenoServer?: Partial<CustomDenoServer>;
|
|
15
|
+
/**
|
|
16
|
+
* Callback executed after server has closed and all inflight requests completed,
|
|
17
|
+
* before process exit. Only applicable in production mode.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* export default createHonoServer({
|
|
22
|
+
* onGracefulShutdown: async () => {
|
|
23
|
+
* await db.close();
|
|
24
|
+
* },
|
|
25
|
+
* });
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
onGracefulShutdown?: () => Promise<void> | void;
|
|
29
|
+
serveStaticOptions?: {
|
|
11
30
|
/**
|
|
12
|
-
* Customize the
|
|
31
|
+
* Customize the public assets (what's in your `public` directory) serve static options.
|
|
13
32
|
*
|
|
14
|
-
* {@link https://docs.deno.com/api/deno/~/Deno.serve#parameters}
|
|
15
33
|
*/
|
|
16
|
-
|
|
34
|
+
publicAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
17
35
|
/**
|
|
18
|
-
*
|
|
19
|
-
* before process exit. Only applicable in production mode.
|
|
36
|
+
* Customize the client assets (what's in your `build/client/assets` directory - React Router) serve static options.
|
|
20
37
|
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* export default createHonoServer({
|
|
24
|
-
* onGracefulShutdown: async () => {
|
|
25
|
-
* await db.close();
|
|
26
|
-
* },
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
38
|
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Customize the public assets (what's in your `public` directory) serve static options.
|
|
34
|
-
*
|
|
35
|
-
*/
|
|
36
|
-
publicAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
37
|
-
/**
|
|
38
|
-
* Customize the client assets (what's in your `build/client/assets` directory - React Router) serve static options.
|
|
39
|
-
*
|
|
40
|
-
*/
|
|
41
|
-
clientAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
42
|
-
};
|
|
39
|
+
clientAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
40
|
+
};
|
|
43
41
|
}
|
|
44
42
|
type HonoServerOptionsWithoutWebSocket<E extends Env = BlankEnv> = HonoDenoServerOptions<E> & WithoutWebsocket<E>;
|
|
45
43
|
type HonoServerOptions<E extends Env = BlankEnv> = HonoDenoServerOptions<E> & Omit<WithoutWebsocket<E>, "useWebSocket">;
|
|
@@ -49,5 +47,5 @@ type HonoServerOptions<E extends Env = BlankEnv> = HonoDenoServerOptions<E> & Om
|
|
|
49
47
|
* @param config {@link HonoServerOptions} - The configuration options for the server
|
|
50
48
|
*/
|
|
51
49
|
declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptionsWithoutWebSocket<E>): Promise<Hono<E>>;
|
|
52
|
-
|
|
53
|
-
export {
|
|
50
|
+
//#endregion
|
|
51
|
+
export { HonoServerOptions, createGetLoadContext, createHonoServer };
|
package/dist/adapters/deno.js
CHANGED
|
@@ -1,110 +1,106 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
createGetLoadContext,
|
|
4
|
-
getBuildMode,
|
|
5
|
-
importBuild
|
|
6
|
-
} from "../chunk-BH64OQMW.js";
|
|
7
|
-
import {
|
|
8
|
-
cache
|
|
9
|
-
} from "../chunk-YI5FED4X.js";
|
|
10
|
-
|
|
11
|
-
// src/adapters/deno.ts
|
|
1
|
+
import { a as getBuildMode, o as importBuild, r as createGetLoadContext, t as bindIncomingRequestSocketInfo } from "../helpers-DpeZU9Bf.js";
|
|
2
|
+
import { cache } from "../middleware.js";
|
|
12
3
|
import { Hono } from "hono";
|
|
13
|
-
import { serveStatic } from "hono/deno";
|
|
14
4
|
import { createMiddleware } from "hono/factory";
|
|
15
5
|
import { logger } from "hono/logger";
|
|
16
6
|
import { createRequestHandler } from "react-router";
|
|
17
|
-
|
|
18
|
-
|
|
7
|
+
import { serveStatic } from "hono/deno";
|
|
8
|
+
//#region src/adapters/deno.ts
|
|
9
|
+
let serverInstance;
|
|
10
|
+
let shutdownCallback;
|
|
19
11
|
async function createHonoServer(options) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
12
|
+
const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
|
|
13
|
+
const mergedOptions = {
|
|
14
|
+
...options,
|
|
15
|
+
port: options?.port || Number(Deno.env.get("PORT")) || 3e3,
|
|
16
|
+
defaultLogger: options?.defaultLogger ?? true
|
|
17
|
+
};
|
|
18
|
+
const mode = getBuildMode();
|
|
19
|
+
const PRODUCTION = mode === "production";
|
|
20
|
+
const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
|
|
21
|
+
const app = new Hono(mergedOptions.app);
|
|
22
|
+
if (PRODUCTION && mergedOptions.onGracefulShutdown) shutdownCallback = mergedOptions.onGracefulShutdown;
|
|
23
|
+
if (!PRODUCTION) app.use(bindIncomingRequestSocketInfo());
|
|
24
|
+
/**
|
|
25
|
+
* Add optional middleware that runs before any built-in middleware, including assets serving.
|
|
26
|
+
*/
|
|
27
|
+
await mergedOptions.beforeAll?.(app);
|
|
28
|
+
/**
|
|
29
|
+
* Serve assets files from build/client/assets
|
|
30
|
+
*/
|
|
31
|
+
app.use(`/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`, cache(3600 * 24 * 365), serveStatic({
|
|
32
|
+
root: clientBuildPath,
|
|
33
|
+
...mergedOptions.serveStaticOptions?.clientAssets
|
|
34
|
+
}));
|
|
35
|
+
/**
|
|
36
|
+
* Serve public files
|
|
37
|
+
*/
|
|
38
|
+
app.use("*", cache(3600), serveStatic({
|
|
39
|
+
root: PRODUCTION ? clientBuildPath : "./public",
|
|
40
|
+
...mergedOptions.serveStaticOptions?.publicAssets
|
|
41
|
+
}));
|
|
42
|
+
/**
|
|
43
|
+
* Add logger middleware
|
|
44
|
+
*/
|
|
45
|
+
if (mergedOptions.defaultLogger) app.use("*", logger());
|
|
46
|
+
/**
|
|
47
|
+
* Add optional middleware
|
|
48
|
+
*/
|
|
49
|
+
await mergedOptions.configure?.(app);
|
|
50
|
+
/**
|
|
51
|
+
* Create a React Router Hono app and bind it to the root Hono server using the React Router basename
|
|
52
|
+
*/
|
|
53
|
+
const reactRouterApp = new Hono({ strict: false });
|
|
54
|
+
reactRouterApp.use(async (c, next) => {
|
|
55
|
+
const build = await importBuild();
|
|
56
|
+
return createMiddleware(async (c) => {
|
|
57
|
+
const requestHandler = createRequestHandler(build, mode);
|
|
58
|
+
const loadContext = mergedOptions.getLoadContext?.(c, {
|
|
59
|
+
build,
|
|
60
|
+
mode
|
|
61
|
+
});
|
|
62
|
+
return requestHandler(c.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
|
|
63
|
+
})(c, next);
|
|
64
|
+
});
|
|
65
|
+
app.route(`${basename}`, reactRouterApp);
|
|
66
|
+
if (basename) app.route(`${basename}.data`, reactRouterApp);
|
|
67
|
+
const server = {
|
|
68
|
+
...mergedOptions.customDenoServer,
|
|
69
|
+
port: mergedOptions.port
|
|
70
|
+
};
|
|
71
|
+
if (PRODUCTION) {
|
|
72
|
+
serverInstance = Deno.serve(server, app.fetch);
|
|
73
|
+
if (shutdownCallback != null) {
|
|
74
|
+
let gracefulShutdownInProgress = false;
|
|
75
|
+
const gracefulShutdown = async (signal) => {
|
|
76
|
+
if (gracefulShutdownInProgress) return;
|
|
77
|
+
gracefulShutdownInProgress = true;
|
|
78
|
+
try {
|
|
79
|
+
if (serverInstance != null) {
|
|
80
|
+
console.log(`\n📡 Received ${signal}, shutting down gracefully...`);
|
|
81
|
+
await serverInstance.shutdown();
|
|
82
|
+
console.log("Server stopped, all requests completed");
|
|
83
|
+
if (shutdownCallback) {
|
|
84
|
+
console.log("🧹 Running cleanup tasks...");
|
|
85
|
+
await shutdownCallback();
|
|
86
|
+
console.log("✅ Cleanup complete!");
|
|
87
|
+
}
|
|
88
|
+
console.log("👋 Graceful shutdown completed");
|
|
89
|
+
}
|
|
90
|
+
process.exit(0);
|
|
91
|
+
} catch (error) {
|
|
92
|
+
console.error("❌ Shutdown failed:", error);
|
|
93
|
+
process.exit(1);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
if (serverInstance != null) {
|
|
97
|
+
process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
|
|
98
|
+
process.on("SIGINT", () => gracefulShutdown("SIGINT"));
|
|
99
|
+
console.log("✅ Graceful shutdown enabled. Press Ctrl+C to shutdown gracefully.");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return app;
|
|
106
104
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
createHonoServer
|
|
110
|
-
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { createGetLoadContext, createHonoServer };
|
package/dist/adapters/node.d.ts
CHANGED
|
@@ -1,88 +1,83 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ServerType } from
|
|
3
|
-
import { ServeStaticOptions } from
|
|
4
|
-
import { Env, Hono } from
|
|
5
|
-
import { BlankEnv } from
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import { ServerOptions as ServerOptions$2, createServer as createServer$2
|
|
10
|
-
import { ServerOptions as ServerOptions$1, createServer as createServer$1 } from 'node:https';
|
|
11
|
-
import 'hono/ws';
|
|
12
|
-
import 'react-router';
|
|
1
|
+
import { i as WithoutWebsocket, n as HonoServerOptionsBase, r as WithWebsocket, t as createGetLoadContext } from "../helpers-CvvzWAWX.js";
|
|
2
|
+
import { ServerType } from "@hono/node-server";
|
|
3
|
+
import { ServeStaticOptions } from "@hono/node-server/serve-static";
|
|
4
|
+
import { Env, Hono } from "hono";
|
|
5
|
+
import { BlankEnv } from "hono/types";
|
|
6
|
+
import { ServerOptions, createServer } from "node:http";
|
|
7
|
+
import { SecureServerOptions, ServerOptions as ServerOptions$1, createSecureServer, createServer as createServer$1 } from "node:http2";
|
|
8
|
+
import { AddressInfo } from "node:net";
|
|
9
|
+
import { ServerOptions as ServerOptions$2, createServer as createServer$2 } from "node:https";
|
|
13
10
|
|
|
11
|
+
//#region src/types/node.https.d.ts
|
|
14
12
|
type createHttpOptions = {
|
|
15
13
|
serverOptions?: ServerOptions;
|
|
16
14
|
createServer?: typeof createServer;
|
|
17
15
|
};
|
|
18
16
|
type createHttpsOptions = {
|
|
19
|
-
serverOptions?: ServerOptions$1;
|
|
20
|
-
createServer?: typeof createServer$1;
|
|
21
|
-
};
|
|
22
|
-
type createHttp2Options = {
|
|
23
17
|
serverOptions?: ServerOptions$2;
|
|
24
18
|
createServer?: typeof createServer$2;
|
|
25
19
|
};
|
|
20
|
+
type createHttp2Options = {
|
|
21
|
+
serverOptions?: ServerOptions$1;
|
|
22
|
+
createServer?: typeof createServer$1;
|
|
23
|
+
};
|
|
26
24
|
type createSecureHttp2Options = {
|
|
27
25
|
serverOptions?: SecureServerOptions;
|
|
28
26
|
createServer?: typeof createSecureServer;
|
|
29
27
|
};
|
|
30
|
-
type CreateNodeServerOptions =
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
| createHttp2Options
|
|
34
|
-
| createSecureHttp2Options;
|
|
35
|
-
|
|
28
|
+
type CreateNodeServerOptions = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region src/adapters/node.d.ts
|
|
36
31
|
interface HonoNodeServerOptions<E extends Env = BlankEnv> extends HonoServerOptionsBase<E> {
|
|
32
|
+
/**
|
|
33
|
+
* Listening listener (production mode only)
|
|
34
|
+
*
|
|
35
|
+
* It is called when the server is listening
|
|
36
|
+
*
|
|
37
|
+
* Defaults log the port
|
|
38
|
+
*/
|
|
39
|
+
listeningListener?: (info: AddressInfo) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Customize the node server (ex: using http2)
|
|
42
|
+
*
|
|
43
|
+
* {@link https://hono.dev/docs/getting-started/nodejs#http2}
|
|
44
|
+
*/
|
|
45
|
+
customNodeServer?: CreateNodeServerOptions;
|
|
46
|
+
/**
|
|
47
|
+
* Callback executed just after `serve` from `@hono/node-server`
|
|
48
|
+
*/
|
|
49
|
+
onServe?: (server: ServerType) => void;
|
|
50
|
+
/**
|
|
51
|
+
* The Node.js Adapter rewrites the global Request/Response and uses a lightweight Request/Response to improve performance.
|
|
52
|
+
*
|
|
53
|
+
* If you this behavior, set it to `true`
|
|
54
|
+
*
|
|
55
|
+
* 🚨 Setting this to `true` can break `request.clone()` if you later check `instanceof Request`.
|
|
56
|
+
*
|
|
57
|
+
* {@link https://github.com/honojs/node-server?tab=readme-ov-file#overrideglobalobjects}
|
|
58
|
+
*
|
|
59
|
+
* @default false
|
|
60
|
+
*/
|
|
61
|
+
overrideGlobalObjects?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Customize the hostname of the node server
|
|
64
|
+
*/
|
|
65
|
+
hostname?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Customize the serve static options
|
|
68
|
+
*/
|
|
69
|
+
serveStaticOptions?: {
|
|
37
70
|
/**
|
|
38
|
-
*
|
|
71
|
+
* Customize the public assets (what's in your `public` directory) serve static options.
|
|
39
72
|
*
|
|
40
|
-
* It is called when the server is listening
|
|
41
|
-
*
|
|
42
|
-
* Defaults log the port
|
|
43
73
|
*/
|
|
44
|
-
|
|
74
|
+
publicAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
45
75
|
/**
|
|
46
|
-
* Customize the
|
|
76
|
+
* Customize the client assets (what's in your `build/client/assets` directory - React Router) serve static options.
|
|
47
77
|
*
|
|
48
|
-
* {@link https://hono.dev/docs/getting-started/nodejs#http2}
|
|
49
|
-
*/
|
|
50
|
-
customNodeServer?: CreateNodeServerOptions;
|
|
51
|
-
/**
|
|
52
|
-
* Callback executed just after `serve` from `@hono/node-server`
|
|
53
78
|
*/
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* The Node.js Adapter rewrites the global Request/Response and uses a lightweight Request/Response to improve performance.
|
|
57
|
-
*
|
|
58
|
-
* If you this behavior, set it to `true`
|
|
59
|
-
*
|
|
60
|
-
* 🚨 Setting this to `true` can break `request.clone()` if you later check `instanceof Request`.
|
|
61
|
-
*
|
|
62
|
-
* {@link https://github.com/honojs/node-server?tab=readme-ov-file#overrideglobalobjects}
|
|
63
|
-
*
|
|
64
|
-
* @default false
|
|
65
|
-
*/
|
|
66
|
-
overrideGlobalObjects?: boolean;
|
|
67
|
-
/**
|
|
68
|
-
* Customize the hostname of the node server
|
|
69
|
-
*/
|
|
70
|
-
hostname?: string;
|
|
71
|
-
/**
|
|
72
|
-
* Customize the serve static options
|
|
73
|
-
*/
|
|
74
|
-
serveStaticOptions?: {
|
|
75
|
-
/**
|
|
76
|
-
* Customize the public assets (what's in your `public` directory) serve static options.
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
publicAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
80
|
-
/**
|
|
81
|
-
* Customize the client assets (what's in your `build/client/assets` directory - React Router) serve static options.
|
|
82
|
-
*
|
|
83
|
-
*/
|
|
84
|
-
clientAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
85
|
-
};
|
|
79
|
+
clientAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
80
|
+
};
|
|
86
81
|
}
|
|
87
82
|
type HonoServerOptionsWithWebSocket<E extends Env = BlankEnv> = HonoNodeServerOptions<E> & WithWebsocket<E>;
|
|
88
83
|
type HonoServerOptionsWithoutWebSocket<E extends Env = BlankEnv> = HonoNodeServerOptions<E> & WithoutWebsocket<E>;
|
|
@@ -94,5 +89,5 @@ type HonoServerOptions<E extends Env = BlankEnv> = HonoServerOptionsWithWebSocke
|
|
|
94
89
|
*/
|
|
95
90
|
declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptionsWithoutWebSocket<E>): Promise<Hono<E>>;
|
|
96
91
|
declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptionsWithWebSocket<E>): Promise<Hono<E>>;
|
|
97
|
-
|
|
98
|
-
export {
|
|
92
|
+
//#endregion
|
|
93
|
+
export { HonoServerOptions, createGetLoadContext, createHonoServer };
|