react-router-hono-server 2.26.0 โ†’ 3.0.0-next.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 CHANGED
@@ -1,4 +1,4 @@
1
- # React Router v7 Hono Server
1
+ # React Router v8 Hono Server
2
2
 
3
3
  <!-- ![GitHub Repo stars](https://img.shields.io/github/stars/rphlmr/react-router-hono-server?style=social)
4
4
  ![npm](https://img.shields.io/npm/v/open-source-stack?style=plastic)
@@ -1,65 +1,20 @@
1
- import * as hono_aws_lambda from 'hono/aws-lambda';
2
- import * as hono_types from 'hono/types';
3
- import { BlankEnv } from 'hono/types';
4
- import { Env, Hono } from 'hono';
5
- import { H as HonoServerOptionsBase, W as WithoutWebsocket } from '../helpers-BXdVojwF.js';
6
- export { c as createGetLoadContext } from '../helpers-BXdVojwF.js';
7
- import 'hono/ws';
8
- import 'react-router';
9
-
10
- interface CognitoIdentity {
11
- cognitoIdentityId: string;
12
- cognitoIdentityPoolId: string;
13
- }
14
- interface ClientContext {
15
- client: ClientContextClient;
16
- Custom?: any;
17
- env: ClientContextEnv;
18
- }
19
- interface ClientContextClient {
20
- installationId: string;
21
- appTitle: string;
22
- appVersionName: string;
23
- appVersionCode: string;
24
- appPackageName: string;
25
- }
26
- interface ClientContextEnv {
27
- platformVersion: string;
28
- platform: string;
29
- make: string;
30
- model: string;
31
- locale: string;
32
- }
33
- /**
34
- * {@link Handler} context parameter.
35
- * See {@link https://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html AWS documentation}.
36
- */
37
- interface LambdaContext {
38
- callbackWaitsForEmptyEventLoop: boolean;
39
- functionName: string;
40
- functionVersion: string;
41
- invokedFunctionArn: string;
42
- memoryLimitInMB: string;
43
- awsRequestId: string;
44
- logGroupName: string;
45
- logStreamName: string;
46
- identity?: CognitoIdentity | undefined;
47
- clientContext?: ClientContext | undefined;
48
- getRemainingTimeInMillis(): number;
49
- }
50
- type Callback<TResult = any> = (error?: Error | string | null, result?: TResult) => void;
51
- type Handler<TEvent = any, TResult = any> = (event: TEvent, context: LambdaContext, callback: Callback<TResult>) => void | Promise<TResult>;
1
+ import { i as WithoutWebsocket, n as HonoServerOptionsBase, t as createGetLoadContext } from "../helpers-CvvzWAWX.js";
2
+ import { Env, Hono } from "hono";
3
+ import { LambdaContext, LambdaEvent } from "hono/aws-lambda";
4
+ import { BlankEnv } from "hono/types";
52
5
 
6
+ //#region src/adapters/aws-lambda.d.ts
53
7
  type InvokeMode = "default" | "stream";
8
+ type AWSLambdaHandler = (event: LambdaEvent, lambdaContext: LambdaContext, callback: (error?: Error | string | null, result?: unknown) => void) => unknown | Promise<unknown>;
54
9
  interface HonoAWSServerOptions<E extends Env = BlankEnv> extends Omit<HonoServerOptionsBase<E>, "port"> {
55
- /**
56
- * The invoke mode to use
57
- *
58
- * Defaults to `default`
59
- *
60
- * {@link https://hono.dev/docs/getting-started/aws-lambda#lambda-response-streaming}
61
- */
62
- invokeMode: InvokeMode;
10
+ /**
11
+ * The invoke mode to use
12
+ *
13
+ * Defaults to `default`
14
+ *
15
+ * {@link https://hono.dev/docs/getting-started/aws-lambda#lambda-response-streaming}
16
+ */
17
+ invokeMode: InvokeMode;
63
18
  }
64
19
  type HonoServerOptions<E extends Env = BlankEnv> = HonoAWSServerOptions<E> & Omit<WithoutWebsocket<E>, "useWebSocket">;
65
20
  /**
@@ -67,14 +22,6 @@ type HonoServerOptions<E extends Env = BlankEnv> = HonoAWSServerOptions<E> & Omi
67
22
  *
68
23
  * @param config {@link HonoServerOptions} - The configuration options for the server
69
24
  */
70
- declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, hono_types.BlankSchema, "/"> | Handler | (<L extends hono_aws_lambda.LambdaEvent>(event: L, lambdaContext?: hono_aws_lambda.LambdaContext) => Promise<hono_aws_lambda.APIGatewayProxyResult & (L extends {
71
- multiValueHeaders: Record<string, string[]>;
72
- } ? {
73
- headers?: undefined;
74
- multiValueHeaders: Record<string, string[]>;
75
- } : {
76
- headers: Record<string, string>;
77
- multiValueHeaders?: undefined;
78
- })>)>;
79
-
80
- export { type HonoServerOptions, createHonoServer };
25
+ declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E> | AWSLambdaHandler>;
26
+ //#endregion
27
+ export { HonoServerOptions, createGetLoadContext, createHonoServer };
@@ -1,78 +1,80 @@
1
- import {
2
- bindIncomingRequestSocketInfo,
3
- createGetLoadContext,
4
- getBuildMode,
5
- importBuild
6
- } from "../chunk-BH64OQMW.js";
7
- import {
8
- cache
9
- } from "../chunk-YI5FED4X.js";
10
-
11
- // src/adapters/aws-lambda.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 { serveStatic } from "@hono/node-server/serve-static";
13
4
  import { Hono } from "hono";
14
- import { handle, streamHandle } from "hono/aws-lambda";
15
5
  import { createMiddleware } from "hono/factory";
16
6
  import { logger } from "hono/logger";
17
7
  import { createRequestHandler } from "react-router";
8
+ import { handle, streamHandle } from "hono/aws-lambda";
9
+ //#region src/adapters/aws-lambda.ts
10
+ /**
11
+ * Create a Hono server
12
+ *
13
+ * @param config {@link HonoServerOptions} - The configuration options for the server
14
+ */
18
15
  async function createHonoServer(options) {
19
- const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
20
- const mergedOptions = {
21
- ...options,
22
- invokeMode: options?.invokeMode ?? "default",
23
- defaultLogger: options?.defaultLogger ?? true
24
- };
25
- const mode = getBuildMode();
26
- const PRODUCTION = mode === "production";
27
- const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
28
- const app = new Hono(mergedOptions.app);
29
- if (!PRODUCTION) {
30
- app.use(bindIncomingRequestSocketInfo());
31
- }
32
- await mergedOptions.beforeAll?.(app);
33
- if (!PRODUCTION) {
34
- app.use(
35
- `/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`,
36
- cache(60 * 60 * 24 * 365),
37
- // 1 year
38
- serveStatic({ root: clientBuildPath })
39
- );
40
- app.use(
41
- "*",
42
- cache(60 * 60),
43
- // 1 hour
44
- serveStatic({ root: PRODUCTION ? clientBuildPath : "./public" })
45
- );
46
- }
47
- if (mergedOptions.defaultLogger) {
48
- app.use("*", logger());
49
- }
50
- await mergedOptions.configure?.(app);
51
- const reactRouterApp = new Hono({
52
- strict: false
53
- });
54
- reactRouterApp.use(async (c, next) => {
55
- const build = await importBuild();
56
- return createMiddleware(async (c2) => {
57
- const requestHandler = createRequestHandler(build, mode);
58
- const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
59
- return requestHandler(c2.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
60
- })(c, next);
61
- });
62
- app.route(`${basename}`, reactRouterApp);
63
- if (basename) {
64
- app.route(`${basename}.data`, reactRouterApp);
65
- }
66
- if (PRODUCTION) {
67
- if (mergedOptions.invokeMode === "stream") {
68
- return streamHandle(app);
69
- }
70
- return handle(app);
71
- }
72
- console.log("\u{1F6A7} Dev server started");
73
- return app;
16
+ const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
17
+ const mergedOptions = {
18
+ ...options,
19
+ invokeMode: options?.invokeMode ?? "default",
20
+ defaultLogger: options?.defaultLogger ?? true
21
+ };
22
+ const mode = getBuildMode();
23
+ const PRODUCTION = mode === "production";
24
+ const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
25
+ const app = new Hono(mergedOptions.app);
26
+ if (!PRODUCTION) app.use(bindIncomingRequestSocketInfo());
27
+ /**
28
+ * Add optional middleware that runs before any built-in middleware, including assets serving.
29
+ */
30
+ await mergedOptions.beforeAll?.(app);
31
+ /**
32
+ * In production, you may use CloudFront or any other AWS services to serve assets
33
+ */
34
+ if (!PRODUCTION) {
35
+ /**
36
+ * Serve assets files from build/client/assets
37
+ */
38
+ app.use(`/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`, cache(3600 * 24 * 365), serveStatic({ root: clientBuildPath }));
39
+ /**
40
+ * Serve public files
41
+ */
42
+ app.use("*", cache(3600), serveStatic({ root: PRODUCTION ? clientBuildPath : "./public" }));
43
+ }
44
+ /**
45
+ * Add logger middleware
46
+ */
47
+ if (mergedOptions.defaultLogger) app.use("*", logger());
48
+ /**
49
+ * Add optional middleware
50
+ */
51
+ await mergedOptions.configure?.(app);
52
+ /**
53
+ * Create a React Router Hono app and bind it to the root Hono server using the React Router basename
54
+ */
55
+ const reactRouterApp = new Hono({ strict: false });
56
+ reactRouterApp.use(async (c, next) => {
57
+ const build = await importBuild();
58
+ return createMiddleware(async (c) => {
59
+ const requestHandler = createRequestHandler(build, mode);
60
+ const loadContext = mergedOptions.getLoadContext?.(c, {
61
+ build,
62
+ mode
63
+ });
64
+ return requestHandler(c.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
65
+ })(c, next);
66
+ });
67
+ app.route(`${basename}`, reactRouterApp);
68
+ if (basename) app.route(`${basename}.data`, reactRouterApp);
69
+ /**
70
+ * Wrap the app in the appropriate AWS handler
71
+ */
72
+ if (PRODUCTION) {
73
+ if (mergedOptions.invokeMode === "stream") return streamHandle(app);
74
+ return handle(app);
75
+ }
76
+ console.log("๐Ÿšง Dev server started");
77
+ return app;
74
78
  }
75
- export {
76
- createGetLoadContext,
77
- createHonoServer
78
- };
79
+ //#endregion
80
+ export { createGetLoadContext, createHonoServer };
@@ -1,49 +1,46 @@
1
- import { Serve } from 'bun';
2
- import { Env } from 'hono';
3
- import { ServeStaticOptions } from 'hono/serve-static';
4
- import { BlankEnv } from 'hono/types';
5
- import { H as HonoServerOptionsBase, a as WithWebsocket, W as WithoutWebsocket } from '../helpers-BXdVojwF.js';
6
- export { c as createGetLoadContext } from '../helpers-BXdVojwF.js';
7
- import 'hono/ws';
8
- import 'react-router';
1
+ import { i as WithoutWebsocket, n as HonoServerOptionsBase, r as WithWebsocket, t as createGetLoadContext } from "../helpers-CvvzWAWX.js";
2
+ import { Env } from "hono";
3
+ import { BlankEnv } from "hono/types";
4
+ import { ServeStaticOptions } from "hono/serve-static";
9
5
 
10
- type CustomBunServer = Serve.Options<unknown, string>;
6
+ //#region src/adapters/bun.d.ts
7
+ type CustomBunServer = Bun.Serve.Options<unknown, string>;
11
8
  interface HonoBunServerOptions<E extends Env = BlankEnv> extends HonoServerOptionsBase<E> {
9
+ /**
10
+ * Customize the bun server
11
+ *
12
+ * {@link https://bun.sh/docs/api/http#start-a-server-bun-serve}
13
+ */
14
+ customBunServer?: Partial<CustomBunServer>;
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
+ /**
30
+ * Customize the serve static options
31
+ */
32
+ serveStaticOptions?: {
12
33
  /**
13
- * Customize the bun server
34
+ * Customize the public assets (what's in your `public` directory) serve static options.
14
35
  *
15
- * {@link https://bun.sh/docs/api/http#start-a-server-bun-serve}
16
36
  */
17
- customBunServer?: Partial<CustomBunServer>;
37
+ publicAssets?: Omit<ServeStaticOptions<E>, "root">;
18
38
  /**
19
- * Callback executed after server has closed and all inflight requests completed,
20
- * before process exit. Only applicable in production mode.
39
+ * Customize the client assets (what's in your `build/client/assets` directory - React Router) serve static options.
21
40
  *
22
- * @example
23
- * ```ts
24
- * export default createHonoServer({
25
- * onGracefulShutdown: async () => {
26
- * await db.close();
27
- * },
28
- * });
29
- * ```
30
41
  */
31
- onGracefulShutdown?: () => Promise<void> | void;
32
- /**
33
- * Customize the serve static options
34
- */
35
- serveStaticOptions?: {
36
- /**
37
- * Customize the public assets (what's in your `public` directory) serve static options.
38
- *
39
- */
40
- publicAssets?: Omit<ServeStaticOptions<E>, "root">;
41
- /**
42
- * Customize the client assets (what's in your `build/client/assets` directory - React Router) serve static options.
43
- *
44
- */
45
- clientAssets?: Omit<ServeStaticOptions<E>, "root">;
46
- };
42
+ clientAssets?: Omit<ServeStaticOptions<E>, "root">;
43
+ };
47
44
  }
48
45
  type HonoServerOptionsWithWebSocket<E extends Env = BlankEnv> = HonoBunServerOptions<E> & WithWebsocket<E>;
49
46
  type HonoServerOptionsWithoutWebSocket<E extends Env = BlankEnv> = HonoBunServerOptions<E> & WithoutWebsocket<E>;
@@ -55,5 +52,5 @@ type HonoServerOptions<E extends Env = BlankEnv> = HonoServerOptionsWithWebSocke
55
52
  */
56
53
  declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptionsWithoutWebSocket<E>): Promise<CustomBunServer>;
57
54
  declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptionsWithWebSocket<E>): Promise<CustomBunServer>;
58
-
59
- export { type HonoServerOptions, createHonoServer };
55
+ //#endregion
56
+ export { HonoServerOptions, createGetLoadContext, createHonoServer };
@@ -1,137 +1,120 @@
1
- import {
2
- bindIncomingRequestSocketInfo,
3
- cleanUpgradeListeners,
4
- createGetLoadContext,
5
- createWebSocket,
6
- getBuildMode,
7
- importBuild,
8
- patchUpgradeListener
9
- } from "../chunk-BH64OQMW.js";
10
- import {
11
- cache
12
- } from "../chunk-YI5FED4X.js";
13
-
14
- // src/adapters/bun.ts
1
+ import { a as getBuildMode, i as createWebSocket, n as cleanUpgradeListeners, o as importBuild, r as createGetLoadContext, s as patchUpgradeListener, t as bindIncomingRequestSocketInfo } from "../helpers-DpeZU9Bf.js";
2
+ import { cache } from "../middleware.js";
15
3
  import { Hono } from "hono";
16
- import { serveStatic } from "hono/bun";
17
4
  import { createMiddleware } from "hono/factory";
18
5
  import { logger } from "hono/logger";
19
6
  import { createRequestHandler } from "react-router";
20
- var serverInstance;
21
- var shutdownCallback;
7
+ import { serveStatic } from "hono/bun";
8
+ //#region src/adapters/bun.ts
9
+ let serverInstance;
10
+ let shutdownCallback;
22
11
  async function createHonoServer(options) {
23
- const build = await importBuild();
24
- const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
25
- const mergedOptions = {
26
- ...options,
27
- port: options?.port || Number(options?.customBunServer?.port) || Number(process.env.PORT) || 3e3,
28
- defaultLogger: options?.defaultLogger ?? true
29
- };
30
- const mode = getBuildMode();
31
- const PRODUCTION = mode === "production";
32
- const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
33
- if (PRODUCTION && mergedOptions.onGracefulShutdown) {
34
- shutdownCallback = mergedOptions.onGracefulShutdown;
35
- }
36
- const app = new Hono(mergedOptions.app);
37
- const { upgradeWebSocket, injectWebSocket } = await createWebSocket({
38
- app,
39
- enabled: mergedOptions.useWebSocket ?? false
40
- });
41
- if (!PRODUCTION) {
42
- app.use(bindIncomingRequestSocketInfo());
43
- }
44
- await mergedOptions.beforeAll?.(app);
45
- app.use(
46
- `/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`,
47
- cache(60 * 60 * 24 * 365),
48
- // 1 year
49
- serveStatic({
50
- root: clientBuildPath,
51
- ...mergedOptions.serveStaticOptions?.clientAssets
52
- })
53
- );
54
- app.use(
55
- "*",
56
- cache(60 * 60),
57
- // 1 hour
58
- serveStatic({
59
- root: PRODUCTION ? clientBuildPath : "./public",
60
- ...mergedOptions.serveStaticOptions?.publicAssets
61
- })
62
- );
63
- if (mergedOptions.defaultLogger) {
64
- app.use("*", logger());
65
- }
66
- if (mergedOptions.useWebSocket) {
67
- await mergedOptions.configure(app, { upgradeWebSocket });
68
- } else {
69
- await mergedOptions.configure?.(app);
70
- }
71
- const reactRouterApp = new Hono({
72
- strict: false
73
- });
74
- reactRouterApp.use((c, next) => {
75
- return createMiddleware(async (c2) => {
76
- const requestHandler = createRequestHandler(build, mode);
77
- const loadContext = mergedOptions.getLoadContext?.(c2, { build, mode });
78
- return requestHandler(c2.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
79
- })(c, next);
80
- });
81
- app.route(`${basename}`, reactRouterApp);
82
- if (basename) {
83
- app.route(`${basename}.data`, reactRouterApp);
84
- }
85
- let server = {
86
- ...mergedOptions.customBunServer,
87
- fetch: app.fetch,
88
- port: mergedOptions.port,
89
- development: !PRODUCTION
90
- };
91
- if (PRODUCTION) {
92
- server = injectWebSocket(server);
93
- serverInstance = Bun.serve(server);
94
- console.log(`Started server: ${serverInstance.protocol}://${serverInstance.hostname}:${serverInstance.port}`);
95
- if (shutdownCallback != null) {
96
- let gracefulShutdownInProgress = false;
97
- const gracefulShutdown = async (signal) => {
98
- if (gracefulShutdownInProgress) return;
99
- gracefulShutdownInProgress = true;
100
- try {
101
- if (serverInstance != null) {
102
- console.log(`
103
- \u{1F4E1} Received ${signal}, shutting down gracefully...`);
104
- await serverInstance.stop(false);
105
- console.log("Server stopped, all requests completed");
106
- if (shutdownCallback) {
107
- console.log("\u{1F9F9} Running cleanup tasks...");
108
- await shutdownCallback();
109
- console.log("\u2705 Cleanup complete!");
110
- }
111
- console.log("\u{1F44B} Graceful shutdown completed");
112
- }
113
- process.exit(0);
114
- } catch (error) {
115
- console.error("\u274C Shutdown failed:", error);
116
- process.exit(1);
117
- }
118
- };
119
- if (serverInstance != null) {
120
- process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
121
- process.on("SIGINT", () => gracefulShutdown("SIGINT"));
122
- console.log("\u2705 Graceful shutdown enabled. Press Ctrl+C to shutdown gracefully.");
123
- }
124
- }
125
- } else if (globalThis.__viteDevServer?.httpServer) {
126
- const httpServer = globalThis.__viteDevServer.httpServer;
127
- cleanUpgradeListeners(httpServer);
128
- injectWebSocket(httpServer);
129
- patchUpgradeListener(httpServer);
130
- console.log("\u{1F6A7} Running in development mode");
131
- }
132
- return server;
12
+ const build = await importBuild();
13
+ const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
14
+ const mergedOptions = {
15
+ ...options,
16
+ port: options?.port || Number(options?.customBunServer?.port) || Number(process.env.PORT) || 3e3,
17
+ defaultLogger: options?.defaultLogger ?? true
18
+ };
19
+ const mode = getBuildMode();
20
+ const PRODUCTION = mode === "production";
21
+ const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
22
+ if (PRODUCTION && mergedOptions.onGracefulShutdown) shutdownCallback = mergedOptions.onGracefulShutdown;
23
+ const app = new Hono(mergedOptions.app);
24
+ const { upgradeWebSocket, injectWebSocket } = await createWebSocket({
25
+ app,
26
+ enabled: mergedOptions.useWebSocket ?? false
27
+ });
28
+ if (!PRODUCTION) app.use(bindIncomingRequestSocketInfo());
29
+ /**
30
+ * Add optional middleware that runs before any built-in middleware, including assets serving.
31
+ */
32
+ await mergedOptions.beforeAll?.(app);
33
+ /**
34
+ * Serve assets files from build/client/assets
35
+ */
36
+ app.use(`/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`, cache(3600 * 24 * 365), serveStatic({
37
+ root: clientBuildPath,
38
+ ...mergedOptions.serveStaticOptions?.clientAssets
39
+ }));
40
+ /**
41
+ * Serve public files
42
+ */
43
+ app.use("*", cache(3600), serveStatic({
44
+ root: PRODUCTION ? clientBuildPath : "./public",
45
+ ...mergedOptions.serveStaticOptions?.publicAssets
46
+ }));
47
+ /**
48
+ * Add logger middleware
49
+ */
50
+ if (mergedOptions.defaultLogger) app.use("*", logger());
51
+ /**
52
+ * Add optional middleware
53
+ */
54
+ if (mergedOptions.useWebSocket) await mergedOptions.configure(app, { upgradeWebSocket });
55
+ else await mergedOptions.configure?.(app);
56
+ /**
57
+ * Create a React Router Hono app and bind it to the root Hono server using the React Router basename
58
+ */
59
+ const reactRouterApp = new Hono({ strict: false });
60
+ reactRouterApp.use((c, next) => {
61
+ return createMiddleware(async (c) => {
62
+ const requestHandler = createRequestHandler(build, mode);
63
+ const loadContext = mergedOptions.getLoadContext?.(c, {
64
+ build,
65
+ mode
66
+ });
67
+ return requestHandler(c.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
68
+ })(c, next);
69
+ });
70
+ app.route(`${basename}`, reactRouterApp);
71
+ if (basename) app.route(`${basename}.data`, reactRouterApp);
72
+ let server = {
73
+ ...mergedOptions.customBunServer,
74
+ fetch: app.fetch,
75
+ port: mergedOptions.port,
76
+ development: !PRODUCTION
77
+ };
78
+ if (PRODUCTION) {
79
+ server = injectWebSocket(server);
80
+ serverInstance = Bun.serve(server);
81
+ if (shutdownCallback != null) {
82
+ let gracefulShutdownInProgress = false;
83
+ const gracefulShutdown = async (signal) => {
84
+ if (gracefulShutdownInProgress) return;
85
+ gracefulShutdownInProgress = true;
86
+ try {
87
+ if (serverInstance != null) {
88
+ console.log(`\n๐Ÿ“ก Received ${signal}, shutting down gracefully...`);
89
+ await serverInstance.stop(false);
90
+ console.log("Server stopped, all requests completed");
91
+ if (shutdownCallback) {
92
+ console.log("๐Ÿงน Running cleanup tasks...");
93
+ await shutdownCallback();
94
+ console.log("โœ… Cleanup complete!");
95
+ }
96
+ console.log("๐Ÿ‘‹ Graceful shutdown completed");
97
+ }
98
+ process.exit(0);
99
+ } catch (error) {
100
+ console.error("โŒ Shutdown failed:", error);
101
+ process.exit(1);
102
+ }
103
+ };
104
+ if (serverInstance != null) {
105
+ process.on("SIGTERM", () => gracefulShutdown("SIGTERM"));
106
+ process.on("SIGINT", () => gracefulShutdown("SIGINT"));
107
+ console.log("โœ… Graceful shutdown enabled. Press Ctrl+C to shutdown gracefully.");
108
+ }
109
+ }
110
+ } else if (globalThis.__viteDevServer?.httpServer) {
111
+ const httpServer = globalThis.__viteDevServer.httpServer;
112
+ cleanUpgradeListeners(httpServer);
113
+ injectWebSocket(httpServer);
114
+ patchUpgradeListener(httpServer);
115
+ console.log("๐Ÿšง Running in development mode");
116
+ }
117
+ return server;
133
118
  }
134
- export {
135
- createGetLoadContext,
136
- createHonoServer
137
- };
119
+ //#endregion
120
+ export { createGetLoadContext, createHonoServer };
@@ -1,19 +1,15 @@
1
- import * as hono_types from 'hono/types';
2
- import { BlankEnv } from 'hono/types';
3
- import { Env, Hono } from 'hono';
4
- import { H as HonoServerOptionsBase, W as WithoutWebsocket } from '../helpers-BXdVojwF.js';
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";
8
4
 
9
- interface HonoCloudflareOptions<E extends Env = BlankEnv> extends Omit<HonoServerOptionsBase<E>, "port"> {
10
- }
5
+ //#region src/adapters/cloudflare.d.ts
6
+ interface HonoCloudflareOptions<E extends Env = BlankEnv> extends Omit<HonoServerOptionsBase<E>, "port"> {}
11
7
  type HonoServerOptions<E extends Env = BlankEnv> = HonoCloudflareOptions<E> & Omit<WithoutWebsocket<E>, "useWebSocket">;
12
8
  /**
13
9
  * Create a Hono server
14
10
  *
15
11
  * @param config {@link HonoServerOptions} - The configuration options for the server
16
12
  */
17
- declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, hono_types.BlankSchema, "/">>;
18
-
19
- export { type HonoServerOptions, createHonoServer };
13
+ declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, import("hono/types").BlankSchema, "/">>;
14
+ //#endregion
15
+ export { HonoServerOptions, createGetLoadContext, createHonoServer };