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/dist/adapters/node.js
CHANGED
|
@@ -1,111 +1,102 @@
|
|
|
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/node.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 { serve } from "@hono/node-server";
|
|
16
4
|
import { serveStatic } from "@hono/node-server/serve-static";
|
|
17
5
|
import { Hono } from "hono";
|
|
18
6
|
import { createMiddleware } from "hono/factory";
|
|
19
7
|
import { logger } from "hono/logger";
|
|
20
8
|
import { createRequestHandler } from "react-router";
|
|
9
|
+
//#region src/adapters/node.ts
|
|
21
10
|
async function createHonoServer(options) {
|
|
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
|
-
|
|
106
|
-
|
|
11
|
+
const startTime = Date.now();
|
|
12
|
+
const build = await importBuild();
|
|
13
|
+
const basename = import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME;
|
|
14
|
+
const mergedOptions = {
|
|
15
|
+
...options,
|
|
16
|
+
listeningListener: options?.listeningListener || ((info) => {
|
|
17
|
+
console.log(`🚀 Server started on port ${info.port}`);
|
|
18
|
+
console.log(`🌍 http://127.0.0.1:${info.port}`);
|
|
19
|
+
if (basename !== "/") console.log(`🔗 http://127.0.0.1:${info.port}${basename}`);
|
|
20
|
+
console.log(`🏎️ Server started in ${Date.now() - startTime}ms`);
|
|
21
|
+
}),
|
|
22
|
+
port: options?.port || Number(process.env.PORT) || 3e3,
|
|
23
|
+
defaultLogger: options?.defaultLogger ?? true,
|
|
24
|
+
overrideGlobalObjects: options?.overrideGlobalObjects ?? false
|
|
25
|
+
};
|
|
26
|
+
const mode = getBuildMode();
|
|
27
|
+
const PRODUCTION = mode === "production";
|
|
28
|
+
const clientBuildPath = `${import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY}/client`;
|
|
29
|
+
const app = new Hono(mergedOptions.app);
|
|
30
|
+
const { upgradeWebSocket, injectWebSocket } = await createWebSocket({
|
|
31
|
+
app,
|
|
32
|
+
enabled: mergedOptions.useWebSocket ?? false
|
|
33
|
+
});
|
|
34
|
+
if (!PRODUCTION) app.use(bindIncomingRequestSocketInfo());
|
|
35
|
+
/**
|
|
36
|
+
* Add optional middleware that runs before any built-in middleware, including assets serving.
|
|
37
|
+
*/
|
|
38
|
+
await mergedOptions.beforeAll?.(app);
|
|
39
|
+
/**
|
|
40
|
+
* Serve assets files from build/client/assets
|
|
41
|
+
*/
|
|
42
|
+
app.use(`/${import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR}/*`, cache(3600 * 24 * 365), serveStatic({
|
|
43
|
+
root: clientBuildPath,
|
|
44
|
+
...mergedOptions.serveStaticOptions?.clientAssets
|
|
45
|
+
}));
|
|
46
|
+
/**
|
|
47
|
+
* Serve public files
|
|
48
|
+
*/
|
|
49
|
+
app.use("*", cache(3600), serveStatic({
|
|
50
|
+
root: PRODUCTION ? clientBuildPath : "./public",
|
|
51
|
+
...mergedOptions.serveStaticOptions?.publicAssets
|
|
52
|
+
}));
|
|
53
|
+
/**
|
|
54
|
+
* Add logger middleware
|
|
55
|
+
*/
|
|
56
|
+
if (mergedOptions.defaultLogger) app.use("*", logger());
|
|
57
|
+
/**
|
|
58
|
+
* Add optional middleware
|
|
59
|
+
*/
|
|
60
|
+
if (mergedOptions.useWebSocket) await mergedOptions.configure(app, { upgradeWebSocket });
|
|
61
|
+
else await mergedOptions.configure?.(app);
|
|
62
|
+
/**
|
|
63
|
+
* Create a React Router Hono app and bind it to the root Hono server using the React Router basename
|
|
64
|
+
*/
|
|
65
|
+
const reactRouterApp = new Hono({ strict: false });
|
|
66
|
+
reactRouterApp.use((c, next) => {
|
|
67
|
+
return createMiddleware(async (c) => {
|
|
68
|
+
const requestHandler = createRequestHandler(build, mode);
|
|
69
|
+
const loadContext = mergedOptions.getLoadContext?.(c, {
|
|
70
|
+
build,
|
|
71
|
+
mode
|
|
72
|
+
});
|
|
73
|
+
return requestHandler(c.req.raw, loadContext instanceof Promise ? await loadContext : loadContext);
|
|
74
|
+
})(c, next);
|
|
75
|
+
});
|
|
76
|
+
app.route(`${basename}`, reactRouterApp);
|
|
77
|
+
if (basename) app.route(`${basename}.data`, reactRouterApp);
|
|
78
|
+
/**
|
|
79
|
+
* Start the production server
|
|
80
|
+
*/
|
|
81
|
+
if (PRODUCTION) {
|
|
82
|
+
const server = serve({
|
|
83
|
+
...app,
|
|
84
|
+
...mergedOptions.customNodeServer,
|
|
85
|
+
port: mergedOptions.port,
|
|
86
|
+
overrideGlobalObjects: mergedOptions.overrideGlobalObjects,
|
|
87
|
+
hostname: mergedOptions.hostname
|
|
88
|
+
}, mergedOptions.listeningListener);
|
|
89
|
+
mergedOptions.onServe?.(server);
|
|
90
|
+
injectWebSocket(server);
|
|
91
|
+
} else if (globalThis.__viteDevServer?.httpServer) {
|
|
92
|
+
const httpServer = globalThis.__viteDevServer.httpServer;
|
|
93
|
+
cleanUpgradeListeners(httpServer);
|
|
94
|
+
mergedOptions.onServe?.(httpServer);
|
|
95
|
+
injectWebSocket(httpServer);
|
|
96
|
+
patchUpgradeListener(httpServer);
|
|
97
|
+
console.log("🚧 Dev server started");
|
|
98
|
+
}
|
|
99
|
+
return app;
|
|
107
100
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
createHonoServer
|
|
111
|
-
};
|
|
101
|
+
//#endregion
|
|
102
|
+
export { createGetLoadContext, createHonoServer };
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/cli.js
CHANGED
|
@@ -1,45 +1,38 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import path from "path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
5
4
|
import { command, run } from "@drizzle-team/brocli";
|
|
6
|
-
|
|
5
|
+
//#region src/cli.ts
|
|
6
|
+
const runtimeRegex = /runtime:\s*(['"])([^'"]*)\1/;
|
|
7
7
|
function guessRuntime() {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
8
|
+
try {
|
|
9
|
+
return fs.readFileSync(path.resolve(process.cwd(), "vite.config.ts"), "utf-8").match(runtimeRegex)?.[2] || "node";
|
|
10
|
+
} catch {
|
|
11
|
+
return "node";
|
|
12
|
+
}
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import { createHonoServer } from "react-router-hono-server/${runtime}";
|
|
14
|
+
const serverFile = `// generated by react-router-hono-server/dev
|
|
15
|
+
import { createHonoServer } from "react-router-hono-server/${guessRuntime()}";
|
|
18
16
|
|
|
19
17
|
export default await createHonoServer();`;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
subcommands: [file, folder]
|
|
42
|
-
});
|
|
43
|
-
run([reveal], {
|
|
44
|
-
name: "React Router Hono Server CLI"
|
|
45
|
-
});
|
|
18
|
+
run([command({
|
|
19
|
+
name: "reveal",
|
|
20
|
+
subcommands: [command({
|
|
21
|
+
name: "file",
|
|
22
|
+
handler() {
|
|
23
|
+
const serverFilePath = path.resolve(process.cwd(), "app", "server.ts");
|
|
24
|
+
fs.writeFileSync(serverFilePath, serverFile);
|
|
25
|
+
console.log(`\x1b[33m✨ File created at ${serverFilePath}\x1b[0m`);
|
|
26
|
+
}
|
|
27
|
+
}), command({
|
|
28
|
+
name: "folder",
|
|
29
|
+
handler() {
|
|
30
|
+
const serverFilePath = path.resolve(process.cwd(), "app", "server", "index.ts");
|
|
31
|
+
if (!fs.existsSync(serverFilePath)) fs.mkdirSync(path.dirname(serverFilePath), { recursive: true });
|
|
32
|
+
fs.writeFileSync(serverFilePath, serverFile);
|
|
33
|
+
console.log(`\x1b[33m✨ Folder and file created at ${serverFilePath}\x1b[0m`);
|
|
34
|
+
}
|
|
35
|
+
})]
|
|
36
|
+
})], { name: "React Router Hono Server CLI" });
|
|
37
|
+
//#endregion
|
|
38
|
+
export {};
|
package/dist/dev.d.ts
CHANGED
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
import { DevServerOptions } from
|
|
2
|
-
import { Plugin } from
|
|
1
|
+
import { DevServerOptions } from "@hono/vite-dev-server";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
3
|
|
|
4
|
+
//#region src/types/runtime.d.ts
|
|
4
5
|
type Runtime = "node" | "bun" | "cloudflare" | "aws" | "deno";
|
|
5
|
-
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/dev.d.ts
|
|
6
8
|
type ReactRouterHonoServerPluginOptionsBase = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
/**
|
|
10
|
+
* The path to the server file, relative to `vite.config.ts`.
|
|
11
|
+
*
|
|
12
|
+
* If it is a folder (`app/server`), it will look for an `index.ts` file.
|
|
13
|
+
*
|
|
14
|
+
* Defaults to `${appDirectory}/server[.ts | /index.ts]` if present.
|
|
15
|
+
*
|
|
16
|
+
* Fallback to a virtual module `virtual:react-router-hono-server/server`.`
|
|
17
|
+
*/
|
|
18
|
+
serverEntryPoint?: string;
|
|
19
|
+
/**
|
|
20
|
+
* The paths that are not served by the dev-server.
|
|
21
|
+
*
|
|
22
|
+
* Defaults include `appDirectory` content.
|
|
23
|
+
*/
|
|
24
|
+
dev?: {
|
|
17
25
|
/**
|
|
18
26
|
* The paths that are not served by the dev-server.
|
|
19
27
|
*
|
|
20
28
|
* Defaults include `appDirectory` content.
|
|
21
29
|
*/
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* The paths that are not served by the dev-server.
|
|
25
|
-
*
|
|
26
|
-
* Defaults include `appDirectory` content.
|
|
27
|
-
*/
|
|
28
|
-
exclude?: DevServerOptions["exclude"];
|
|
29
|
-
/**
|
|
30
|
-
* The name of the export to use for the server.
|
|
31
|
-
*
|
|
32
|
-
* Defaults to `default`.
|
|
33
|
-
*/
|
|
34
|
-
export?: DevServerOptions["export"];
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
type ReactRouterHonoServerPluginOptionsDefault = ReactRouterHonoServerPluginOptionsBase & {
|
|
30
|
+
exclude?: DevServerOptions["exclude"];
|
|
38
31
|
/**
|
|
39
|
-
* The
|
|
32
|
+
* The name of the export to use for the server.
|
|
40
33
|
*
|
|
41
|
-
* Defaults to `
|
|
34
|
+
* Defaults to `default`.
|
|
42
35
|
*/
|
|
43
|
-
|
|
36
|
+
export?: DevServerOptions["export"];
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
type ReactRouterHonoServerPluginOptionsDefault = ReactRouterHonoServerPluginOptionsBase & {
|
|
40
|
+
/**
|
|
41
|
+
* The runtime to use for the server.
|
|
42
|
+
*
|
|
43
|
+
* Defaults to `node`.
|
|
44
|
+
*/
|
|
45
|
+
runtime?: Runtime;
|
|
44
46
|
};
|
|
45
47
|
type ReactRouterHonoServerPluginOptionsCloudflare = ReactRouterHonoServerPluginOptionsBase & {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
/**
|
|
49
|
+
* The runtime to use for the server.
|
|
50
|
+
*
|
|
51
|
+
* Defaults to `node`.
|
|
52
|
+
*/
|
|
53
|
+
runtime: Extract<Runtime, "cloudflare">;
|
|
54
|
+
flag?: {
|
|
55
|
+
force_react_19?: boolean;
|
|
56
|
+
};
|
|
55
57
|
};
|
|
56
58
|
type ReactRouterHonoServerPluginOptions = ReactRouterHonoServerPluginOptionsDefault | ReactRouterHonoServerPluginOptionsCloudflare;
|
|
57
59
|
declare function reactRouterHonoServer(options?: ReactRouterHonoServerPluginOptions): Plugin;
|
|
58
|
-
|
|
59
|
-
export { reactRouterHonoServer };
|
|
60
|
+
//#endregion
|
|
61
|
+
export { reactRouterHonoServer };
|