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 +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
package/README.md
CHANGED
|
@@ -1,65 +1,20 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
|
71
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
createHonoServer
|
|
78
|
-
};
|
|
79
|
+
//#endregion
|
|
80
|
+
export { createGetLoadContext, createHonoServer };
|
package/dist/adapters/bun.d.ts
CHANGED
|
@@ -1,49 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Env } from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
37
|
+
publicAssets?: Omit<ServeStaticOptions<E>, "root">;
|
|
18
38
|
/**
|
|
19
|
-
*
|
|
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
|
-
|
|
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 {
|
|
55
|
+
//#endregion
|
|
56
|
+
export { HonoServerOptions, createGetLoadContext, createHonoServer };
|
package/dist/adapters/bun.js
CHANGED
|
@@ -1,137 +1,120 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
135
|
-
|
|
136
|
-
createHonoServer
|
|
137
|
-
};
|
|
119
|
+
//#endregion
|
|
120
|
+
export { createGetLoadContext, createHonoServer };
|
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
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,
|
|
18
|
-
|
|
19
|
-
export {
|
|
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 };
|