react-router-hono-server 2.24.0 → 2.25.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 +14 -0
- package/dist/adapters/bun.d.ts +14 -0
- package/dist/adapters/bun.js +37 -0
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -664,6 +664,20 @@ export interface HonoServerOptions<E extends Env = BlankEnv> extends HonoServerO
|
|
|
664
664
|
* {@link https://bun.sh/docs/api/http#start-a-server-bun-serve}
|
|
665
665
|
*/
|
|
666
666
|
customBunServer?: Serve.Options<unknown, string>;
|
|
667
|
+
/**
|
|
668
|
+
* Callback executed after server has closed and all inflight requests completed,
|
|
669
|
+
* before process exit. Only applicable in production mode.
|
|
670
|
+
*
|
|
671
|
+
* @example
|
|
672
|
+
* ```ts
|
|
673
|
+
* export default createHonoServer({
|
|
674
|
+
* onGracefulShutdown: async () => {
|
|
675
|
+
* await db.close();
|
|
676
|
+
* },
|
|
677
|
+
* });
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
onGracefulShutdown?: () => Promise<void> | void;
|
|
667
681
|
/**
|
|
668
682
|
* Customize the serve static options
|
|
669
683
|
*/
|
package/dist/adapters/bun.d.ts
CHANGED
|
@@ -15,6 +15,20 @@ interface HonoBunServerOptions<E extends Env = BlankEnv> extends HonoServerOptio
|
|
|
15
15
|
* {@link https://bun.sh/docs/api/http#start-a-server-bun-serve}
|
|
16
16
|
*/
|
|
17
17
|
customBunServer?: Partial<CustomBunServer>;
|
|
18
|
+
/**
|
|
19
|
+
* Callback executed after server has closed and all inflight requests completed,
|
|
20
|
+
* before process exit. Only applicable in production mode.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* export default createHonoServer({
|
|
25
|
+
* onGracefulShutdown: async () => {
|
|
26
|
+
* await db.close();
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
onGracefulShutdown?: () => Promise<void> | void;
|
|
18
32
|
/**
|
|
19
33
|
* Customize the serve static options
|
|
20
34
|
*/
|
package/dist/adapters/bun.js
CHANGED
|
@@ -17,6 +17,8 @@ import { serveStatic } from "hono/bun";
|
|
|
17
17
|
import { createMiddleware } from "hono/factory";
|
|
18
18
|
import { logger } from "hono/logger";
|
|
19
19
|
import { createRequestHandler } from "react-router";
|
|
20
|
+
var serverInstance;
|
|
21
|
+
var shutdownCallback;
|
|
20
22
|
async function createHonoServer(options) {
|
|
21
23
|
const build = await importBuild();
|
|
22
24
|
const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
|
|
@@ -28,6 +30,9 @@ async function createHonoServer(options) {
|
|
|
28
30
|
const mode = getBuildMode();
|
|
29
31
|
const PRODUCTION = mode === "production";
|
|
30
32
|
const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
|
|
33
|
+
if (PRODUCTION && mergedOptions.onGracefulShutdown) {
|
|
34
|
+
shutdownCallback = mergedOptions.onGracefulShutdown;
|
|
35
|
+
}
|
|
31
36
|
const app = new Hono(mergedOptions.app);
|
|
32
37
|
const { upgradeWebSocket, injectWebSocket } = await createWebSocket({
|
|
33
38
|
app,
|
|
@@ -85,6 +90,38 @@ async function createHonoServer(options) {
|
|
|
85
90
|
};
|
|
86
91
|
if (PRODUCTION) {
|
|
87
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
|
+
}
|
|
88
125
|
} else if (globalThis.__viteDevServer?.httpServer) {
|
|
89
126
|
const httpServer = globalThis.__viteDevServer.httpServer;
|
|
90
127
|
cleanUpgradeListeners(httpServer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.25.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
|
|
6
6
|
"publishConfig": {
|
|
@@ -78,16 +78,16 @@
|
|
|
78
78
|
"@drizzle-team/brocli": "0.11.0",
|
|
79
79
|
"@hono/node-server": "1.19.9",
|
|
80
80
|
"@hono/node-ws": "1.3.0",
|
|
81
|
-
"@hono/vite-dev-server": "0.
|
|
82
|
-
"hono": "4.11.7"
|
|
81
|
+
"@hono/vite-dev-server": "0.25.0"
|
|
83
82
|
},
|
|
84
83
|
"devDependencies": {
|
|
85
84
|
"@biomejs/biome": "^2.3.1",
|
|
86
85
|
"@changesets/cli": "^2.29.8",
|
|
87
86
|
"@cloudflare/workers-types": "^4.20250405.0",
|
|
88
87
|
"@types/bun": "^1.3.6",
|
|
89
|
-
"@types/node": "^22.19.
|
|
88
|
+
"@types/node": "^22.19.10",
|
|
90
89
|
"@vitest/coverage-v8": "^4.0.18",
|
|
90
|
+
"hono": "4.11.9",
|
|
91
91
|
"lefthook": "^2.0.16",
|
|
92
92
|
"npm-run-all": "^4.1.5",
|
|
93
93
|
"tsup": "^8.5.1",
|
|
@@ -99,6 +99,7 @@
|
|
|
99
99
|
"@hono/node-server": "^1.19.0",
|
|
100
100
|
"@react-router/dev": "^7.9.0",
|
|
101
101
|
"@types/react": "^19.0.0",
|
|
102
|
+
"hono": "^4.11.0",
|
|
102
103
|
"miniflare": "^3.20241205.0",
|
|
103
104
|
"react-router": "^7.9.0",
|
|
104
105
|
"vite": "^7.0.0",
|