react-router-hono-server 3.0.0 → 4.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 +556 -985
- package/dist/adapters/aws-lambda.d.ts +2 -3
- package/dist/adapters/aws-lambda.js +5 -3
- package/dist/adapters/bun.d.ts +1 -2
- package/dist/adapters/bun.js +22 -22
- package/dist/adapters/cloudflare.d.ts +8 -4
- package/dist/adapters/cloudflare.js +14 -12
- package/dist/adapters/deno.d.ts +4 -3
- package/dist/adapters/deno.js +30 -18
- package/dist/adapters/node.d.ts +15 -3
- package/dist/adapters/node.js +16 -16
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +24 -20
- package/dist/dev.d.ts +1 -13
- package/dist/dev.js +54 -55
- package/dist/{helpers-DpeZU9Bf.js → helpers-D9Y2AQRk.js} +60 -11
- package/dist/{helpers-CvvzWAWX.d.ts → helpers-VHYCCAPs.d.ts} +13 -25
- package/dist/http.d.ts +0 -1
- package/dist/http.js +2 -2
- package/dist/react-router-build-request-_jlIVza5.js +7 -0
- package/package.json +80 -59
package/dist/dev.js
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import path from "node:path";
|
|
1
|
+
import { t as isReactRouterBuildRequest } from "./react-router-build-request-_jlIVza5.js";
|
|
3
2
|
import honoDevServer from "@hono/vite-dev-server";
|
|
4
3
|
import bunAdapter from "@hono/vite-dev-server/bun";
|
|
5
4
|
import nodeAdapter from "@hono/vite-dev-server/node";
|
|
5
|
+
import fs from "node:fs";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
6
8
|
//#region src/dev.ts
|
|
7
9
|
const REACT_ROUTER_SERVER_BUILD_MODULE_ID = "\0virtual:react-router/server-build";
|
|
8
10
|
const VIRTUAL_MODULE_ID = "\0virtual:react-router-hono-server/server";
|
|
9
|
-
const REACT_ROUTER_EXPORT = "export { serverManifest as assets, assetsBuildDirectory, basename, entry, future, isSpaMode, prerender, publicPath, routes, ssr, routeDiscovery };";
|
|
10
11
|
function reactRouterHonoServer(options = {}) {
|
|
11
12
|
const runtime = options.runtime || "node";
|
|
13
|
+
const adapterEntryPoint = runtime === "aws" ? "aws-lambda" : runtime;
|
|
12
14
|
let pluginConfig;
|
|
13
15
|
let devServerPlugin;
|
|
16
|
+
let previewAppPromise;
|
|
14
17
|
return {
|
|
15
18
|
name: "react-router-hono-server",
|
|
16
19
|
enforce: "post",
|
|
@@ -20,16 +23,19 @@ function reactRouterHonoServer(options = {}) {
|
|
|
20
23
|
load(id) {
|
|
21
24
|
if (id === VIRTUAL_MODULE_ID) return `
|
|
22
25
|
// generated by react-router-hono-server/dev
|
|
23
|
-
import { createHonoServer } from "react-router-hono-server/${
|
|
26
|
+
import { createHonoServer } from "react-router-hono-server/${adapterEntryPoint}";
|
|
24
27
|
|
|
25
28
|
export default await createHonoServer();
|
|
26
29
|
`;
|
|
27
30
|
},
|
|
28
|
-
|
|
31
|
+
configResolved(config) {
|
|
32
|
+
if (runtime === "cloudflare" && !config.plugins.some((plugin) => plugin.name === "vite-plugin-cloudflare" || plugin.name.startsWith("vite-plugin-cloudflare:"))) throw new Error("Missing cloudflare() in vite.config.ts. Add it with: import { cloudflare } from \"@cloudflare/vite-plugin\".");
|
|
33
|
+
},
|
|
34
|
+
config(config, env) {
|
|
29
35
|
pluginConfig = resolvePluginConfig(config, options);
|
|
30
36
|
if (!pluginConfig) return;
|
|
31
37
|
const serverEntryPoint = pluginConfig.serverEntryPoint;
|
|
32
|
-
|
|
38
|
+
const denoDevReactExternals = runtime === "deno" && env.mode === "development" ? ["react", "react-dom"] : [];
|
|
33
39
|
const baseConfig = {
|
|
34
40
|
define: {
|
|
35
41
|
"import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY": JSON.stringify(pluginConfig.buildDirectory),
|
|
@@ -40,7 +46,7 @@ function reactRouterHonoServer(options = {}) {
|
|
|
40
46
|
ssr: {
|
|
41
47
|
target: runtime === "cloudflare" ? "webworker" : void 0,
|
|
42
48
|
noExternal: ["react-router-hono-server"],
|
|
43
|
-
external: [
|
|
49
|
+
...runtime === "cloudflare" ? {} : { external: [...denoDevReactExternals] },
|
|
44
50
|
optimizeDeps: runtime === "bun" ? {
|
|
45
51
|
include: ["react-dom/server"],
|
|
46
52
|
exclude: ["react"]
|
|
@@ -50,13 +56,16 @@ function reactRouterHonoServer(options = {}) {
|
|
|
50
56
|
let reactRouterBuildFile = pluginConfig.serverBuildFile;
|
|
51
57
|
if (reactRouterBuildFile === "index.js") reactRouterBuildFile = "assets/server-build.js";
|
|
52
58
|
const resolve = {};
|
|
53
|
-
if (runtime === "cloudflare") resolve.alias = { "react-dom/server":
|
|
54
|
-
if (runtime === "bun") resolve.alias = { "react-dom/server": "react-dom/server.
|
|
55
|
-
if (runtime === "deno") resolve.alias = { "react-dom/server": "react-dom/server.
|
|
59
|
+
if (runtime === "cloudflare") resolve.alias = { "react-dom/server": "react-dom/server.edge" };
|
|
60
|
+
if (runtime === "bun") resolve.alias = { "react-dom/server": "react-dom/server.browser" };
|
|
61
|
+
if (runtime === "deno" && env.mode !== "development") resolve.alias = { "react-dom/server": "react-dom/server.browser" };
|
|
56
62
|
const ssrConfig = {
|
|
57
|
-
resolve
|
|
63
|
+
resolve: {
|
|
64
|
+
...resolve,
|
|
65
|
+
...denoDevReactExternals.length > 0 ? { external: denoDevReactExternals } : {}
|
|
66
|
+
},
|
|
58
67
|
build: { rollupOptions: {
|
|
59
|
-
input: serverEntryPoint,
|
|
68
|
+
...runtime === "cloudflare" ? {} : { input: serverEntryPoint },
|
|
60
69
|
output: {
|
|
61
70
|
entryFileNames: (chunk) => {
|
|
62
71
|
chunk.facadeModuleId = REACT_ROUTER_SERVER_BUILD_MODULE_ID;
|
|
@@ -68,8 +77,7 @@ function reactRouterHonoServer(options = {}) {
|
|
|
68
77
|
},
|
|
69
78
|
manualChunks: runtime !== "cloudflare" ? (id, meta) => {
|
|
70
79
|
if (meta.getModuleInfo(id)?.importers.some((id) => id.includes(serverEntryPoint))) return path.basename(id, path.extname(id));
|
|
71
|
-
} : void 0
|
|
72
|
-
footer: runtime === "cloudflare" ? REACT_ROUTER_EXPORT : void 0
|
|
80
|
+
} : void 0
|
|
73
81
|
}
|
|
74
82
|
} }
|
|
75
83
|
};
|
|
@@ -79,33 +87,13 @@ function reactRouterHonoServer(options = {}) {
|
|
|
79
87
|
environments: { ssr: ssrConfig }
|
|
80
88
|
};
|
|
81
89
|
},
|
|
82
|
-
|
|
83
|
-
if (!pluginConfig?.isSsrBuild || runtime !== "cloudflare") return;
|
|
84
|
-
console.log("Cleaning up server exports...");
|
|
85
|
-
const buildPath = path.join(pluginConfig.rootDirectory, pluginConfig.buildDirectory, "server", "index.js");
|
|
86
|
-
let serverFile = await fs.promises.readFile(buildPath, "utf-8").catch((e) => {
|
|
87
|
-
if (e.code === "ENOENT") {
|
|
88
|
-
console.error("\x1B[31m\nThe server was not built\x1B[0m");
|
|
89
|
-
if (pluginConfig?.flag?.force_react_19) console.error("\x1B[31m\nYou are forcing React 19 but the server failed to be built by React Router.\nCheck your dependencies, but it's possible that your project is still using React 18 from a node_modules root (monorepo?)\n\x1B[0m");
|
|
90
|
-
}
|
|
91
|
-
return null;
|
|
92
|
-
});
|
|
93
|
-
if (!serverFile) return;
|
|
94
|
-
serverFile = serverFile.replace(REACT_ROUTER_EXPORT, "");
|
|
95
|
-
if (await getReactVersion(pluginConfig) >= 19) serverFile = serverFile.replace(/react-dom\/server\.browser/g, "react-dom/server.edge");
|
|
96
|
-
await fs.promises.writeFile(buildPath, serverFile);
|
|
97
|
-
console.log("\x1B[32mAll done!\x1B[0m");
|
|
98
|
-
},
|
|
99
|
-
async configureServer(server) {
|
|
90
|
+
configureServer(server) {
|
|
100
91
|
globalThis.__viteDevServer = server;
|
|
101
92
|
if (!pluginConfig) return;
|
|
93
|
+
if (runtime === "cloudflare") return;
|
|
102
94
|
if (devServerPlugin) return;
|
|
103
95
|
let adapter = nodeAdapter;
|
|
104
96
|
if (runtime === "bun") adapter = bunAdapter;
|
|
105
|
-
if (runtime === "cloudflare") {
|
|
106
|
-
const { cloudflareAdapter } = await import("@hono/vite-dev-server/cloudflare");
|
|
107
|
-
adapter = cloudflareAdapter;
|
|
108
|
-
}
|
|
109
97
|
if (runtime === "deno") adapter = () => {
|
|
110
98
|
if (typeof globalThis.navigator === "undefined") globalThis.navigator = { userAgent: "Deno" };
|
|
111
99
|
else Object.defineProperty(globalThis.navigator, "userAgent", {
|
|
@@ -141,6 +129,35 @@ function reactRouterHonoServer(options = {}) {
|
|
|
141
129
|
console.error("Dev server plugin configureServer hook is not a function. This is likely a bug, I guess 😅\n");
|
|
142
130
|
throw new Error("Cannot apply dev server plugin configureServer hook");
|
|
143
131
|
}
|
|
132
|
+
},
|
|
133
|
+
configurePreviewServer(server) {
|
|
134
|
+
server.middlewares.use((req, res, next) => {
|
|
135
|
+
if (runtime === "cloudflare" || !isReactRouterBuildRequest() || !pluginConfig) {
|
|
136
|
+
next();
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
(async () => {
|
|
140
|
+
try {
|
|
141
|
+
previewAppPromise ??= import(pathToFileURL(path.resolve(pluginConfig.rootDirectory, pluginConfig.buildDirectory, "server/index.js")).href).then((module) => module.default);
|
|
142
|
+
const app = await previewAppPromise;
|
|
143
|
+
const headers = new Headers();
|
|
144
|
+
for (const [name, value] of Object.entries(req.headers)) for (const item of Array.isArray(value) ? value : [value]) if (item !== void 0) headers.append(name, item);
|
|
145
|
+
const request = new Request(`http://${req.headers.host ?? "localhost"}${req.url ?? "/"}`, {
|
|
146
|
+
method: req.method,
|
|
147
|
+
headers
|
|
148
|
+
});
|
|
149
|
+
const response = await app.fetch(request);
|
|
150
|
+
res.statusCode = response.status;
|
|
151
|
+
response.headers.forEach((value, name) => {
|
|
152
|
+
res.setHeader(name, value);
|
|
153
|
+
});
|
|
154
|
+
res.end(Buffer.from(await response.arrayBuffer()));
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error(error);
|
|
157
|
+
next(error);
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
});
|
|
144
161
|
}
|
|
145
162
|
};
|
|
146
163
|
}
|
|
@@ -154,7 +171,6 @@ function resolvePluginConfig(config, options) {
|
|
|
154
171
|
const serverEntryPoint = options.serverEntryPoint || findDefaultServerEntry(appDirectory);
|
|
155
172
|
const serverBuildFile = reactRouterConfig.serverBuildFile;
|
|
156
173
|
const basename = reactRouterConfig.basename;
|
|
157
|
-
const future = reactRouterConfig.future;
|
|
158
174
|
return {
|
|
159
175
|
rootDirectory,
|
|
160
176
|
buildDirectory,
|
|
@@ -164,9 +180,7 @@ function resolvePluginConfig(config, options) {
|
|
|
164
180
|
serverEntryPoint,
|
|
165
181
|
dev: options.dev,
|
|
166
182
|
serverBuildFile,
|
|
167
|
-
basename
|
|
168
|
-
future,
|
|
169
|
-
flag: isCloudflareOptions(options) ? options.flag : {}
|
|
183
|
+
basename
|
|
170
184
|
};
|
|
171
185
|
}
|
|
172
186
|
let warned = false;
|
|
@@ -181,20 +195,5 @@ function findDefaultServerEntry(appDirectory) {
|
|
|
181
195
|
}
|
|
182
196
|
return VIRTUAL_MODULE_ID;
|
|
183
197
|
}
|
|
184
|
-
/**
|
|
185
|
-
* Retrieves the major React version from node_modules
|
|
186
|
-
*/
|
|
187
|
-
async function getReactVersion(pluginConfig) {
|
|
188
|
-
if (pluginConfig?.flag?.force_react_19) return 19;
|
|
189
|
-
const reactPackage = await import("react");
|
|
190
|
-
const version = reactPackage.default.version || reactPackage.version;
|
|
191
|
-
return Number.parseInt(version.split(".")[0], 10);
|
|
192
|
-
}
|
|
193
|
-
/**
|
|
194
|
-
* Type guard to check if options is the Cloudflare variant
|
|
195
|
-
*/
|
|
196
|
-
function isCloudflareOptions(options) {
|
|
197
|
-
return options.runtime === "cloudflare";
|
|
198
|
-
}
|
|
199
198
|
//#endregion
|
|
200
199
|
export { reactRouterHonoServer };
|
|
@@ -4,12 +4,20 @@ const defaultWebSocket = {
|
|
|
4
4
|
upgradeWebSocket: (() => {}),
|
|
5
5
|
injectWebSocket: (server) => server
|
|
6
6
|
};
|
|
7
|
+
async function importNodeWebSocket(runtime, mode) {
|
|
8
|
+
try {
|
|
9
|
+
return await import("ws");
|
|
10
|
+
} catch (cause) {
|
|
11
|
+
throw new Error(`WebSocket support for the "${runtime}" runtime in ${mode} requires the optional "ws" peer dependency. Install "ws" before enabling useWebSocket.`, { cause });
|
|
12
|
+
}
|
|
13
|
+
}
|
|
7
14
|
/**
|
|
8
15
|
* Create WebSocket factory
|
|
9
16
|
*
|
|
10
|
-
* It harmonizes the WebSocket implementation between
|
|
17
|
+
* It harmonizes the WebSocket implementation between supported runtimes.
|
|
11
18
|
*
|
|
12
|
-
*
|
|
19
|
+
* Node, Bun development, and Deno development use `@hono/node-server`.
|
|
20
|
+
* Cloudflare always uses Workerd's native implementation.
|
|
13
21
|
*
|
|
14
22
|
* **Implementation details: It will strip unused code from other runtimes at build time**
|
|
15
23
|
*
|
|
@@ -17,17 +25,30 @@ const defaultWebSocket = {
|
|
|
17
25
|
*/
|
|
18
26
|
async function createWebSocket({ app, enabled }) {
|
|
19
27
|
if (!enabled) return defaultWebSocket;
|
|
20
|
-
const
|
|
28
|
+
const mode = process.env.NODE_ENV === "development" ? "development" : "production";
|
|
29
|
+
const DEV = mode === "development";
|
|
21
30
|
const runtime = import.meta.env.REACT_ROUTER_HONO_SERVER_RUNTIME;
|
|
22
|
-
if (
|
|
23
|
-
const {
|
|
24
|
-
|
|
31
|
+
if (runtime === "cloudflare") {
|
|
32
|
+
const { upgradeWebSocket } = await import("hono/cloudflare-workers");
|
|
33
|
+
return {
|
|
34
|
+
upgradeWebSocket,
|
|
35
|
+
injectWebSocket: (server) => server
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
if (runtime === "node" || DEV && (runtime === "bun" || runtime === "deno")) {
|
|
39
|
+
const [{ createAdaptorServer, upgradeWebSocket }, { WebSocketServer }] = await Promise.all([import("@hono/node-server"), importNodeWebSocket(runtime, mode)]);
|
|
40
|
+
const websocket = { server: new WebSocketServer({ noServer: true }) };
|
|
25
41
|
return {
|
|
26
42
|
upgradeWebSocket,
|
|
27
43
|
injectWebSocket(server) {
|
|
28
|
-
|
|
44
|
+
createAdaptorServer({
|
|
45
|
+
fetch: app.fetch,
|
|
46
|
+
websocket,
|
|
47
|
+
createServer: (() => server)
|
|
48
|
+
});
|
|
29
49
|
return server;
|
|
30
|
-
}
|
|
50
|
+
},
|
|
51
|
+
nodeWebSocket: websocket
|
|
31
52
|
};
|
|
32
53
|
}
|
|
33
54
|
if (runtime === "bun") {
|
|
@@ -43,12 +64,31 @@ async function createWebSocket({ app, enabled }) {
|
|
|
43
64
|
}
|
|
44
65
|
};
|
|
45
66
|
}
|
|
67
|
+
if (runtime === "deno") {
|
|
68
|
+
const { upgradeWebSocket } = await import("hono/deno");
|
|
69
|
+
return {
|
|
70
|
+
upgradeWebSocket,
|
|
71
|
+
injectWebSocket: (server) => server
|
|
72
|
+
};
|
|
73
|
+
}
|
|
46
74
|
return defaultWebSocket;
|
|
47
75
|
}
|
|
48
76
|
/**
|
|
77
|
+
* Attach the Node WebSocket bridge to Vite's HTTP server without intercepting HMR.
|
|
78
|
+
*/
|
|
79
|
+
function attachWebSocketToVite(injectWebSocket, onServe) {
|
|
80
|
+
const httpServer = globalThis.__viteDevServer?.httpServer;
|
|
81
|
+
if (!httpServer) return false;
|
|
82
|
+
cleanUpgradeListeners(httpServer);
|
|
83
|
+
onServe?.(httpServer);
|
|
84
|
+
injectWebSocket(httpServer);
|
|
85
|
+
patchUpgradeListener(httpServer);
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
49
89
|
* Clean all user-defined upgrade listeners, except HMR
|
|
50
90
|
*
|
|
51
|
-
* Avoid conflicts on
|
|
91
|
+
* Avoid conflicts on already-upgraded connections when using Node WebSockets in dev.
|
|
52
92
|
*
|
|
53
93
|
*/
|
|
54
94
|
function cleanUpgradeListeners(httpServer) {
|
|
@@ -87,10 +127,19 @@ function bindIncomingRequestSocketInfo() {
|
|
|
87
127
|
});
|
|
88
128
|
}
|
|
89
129
|
/**
|
|
130
|
+
* Prevent Chrome DevTools workspace discovery from reaching React Router's catch-all route.
|
|
131
|
+
*
|
|
132
|
+
* Public files and user-defined routes are registered first so applications can opt into
|
|
133
|
+
* automatic workspace discovery.
|
|
134
|
+
*/
|
|
135
|
+
function handleChromeDevToolsWorkspaceRequest(app) {
|
|
136
|
+
app.get("/.well-known/appspecific/com.chrome.devtools.json", (c) => c.notFound());
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
90
139
|
* Import React Router server build
|
|
91
140
|
*/
|
|
92
141
|
async function importBuild() {
|
|
93
|
-
return
|
|
142
|
+
return import("virtual:react-router/server-build");
|
|
94
143
|
}
|
|
95
144
|
/**
|
|
96
145
|
* Helper to create a getLoadContext function fully typed
|
|
@@ -105,4 +154,4 @@ function getBuildMode() {
|
|
|
105
154
|
return process.env.NODE_ENV === "development" ? "development" : "production";
|
|
106
155
|
}
|
|
107
156
|
//#endregion
|
|
108
|
-
export { getBuildMode as a, createWebSocket as i,
|
|
157
|
+
export { getBuildMode as a, createWebSocket as i, bindIncomingRequestSocketInfo as n, handleChromeDevToolsWorkspaceRequest as o, createGetLoadContext as r, importBuild as s, attachWebSocketToVite as t };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ServerType } from "@hono/node-server";
|
|
2
2
|
import { Context, Env, Hono } from "hono";
|
|
3
|
-
import {
|
|
3
|
+
import { RouterContextProvider, ServerBuild } from "react-router";
|
|
4
4
|
import { UpgradeWebSocket } from "hono/ws";
|
|
5
|
-
|
|
5
|
+
import { WebSocketServer } from "ws";
|
|
6
6
|
//#region src/types/hono-server-options-base.d.ts
|
|
7
|
-
type ReactRouterHonoServerAppLoadContext =
|
|
7
|
+
type ReactRouterHonoServerAppLoadContext = RouterContextProvider;
|
|
8
8
|
interface HonoServerOptionsBase<E extends Env> {
|
|
9
9
|
/**
|
|
10
10
|
* The base Hono app to use as a replacement for the default one created automatically
|
|
@@ -28,27 +28,15 @@ interface HonoServerOptionsBase<E extends Env> {
|
|
|
28
28
|
*/
|
|
29
29
|
port?: number;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Create the React Router load context.
|
|
32
32
|
*
|
|
33
|
-
*
|
|
33
|
+
* React Router 8 requires a `RouterContextProvider`. Define values with
|
|
34
|
+
* `createContext` and set them on the provider.
|
|
34
35
|
*
|
|
35
36
|
* ```ts
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
* whatever: string;
|
|
40
|
-
* }
|
|
41
|
-
* }
|
|
42
|
-
* ```
|
|
43
|
-
*
|
|
44
|
-
* **To make the typing works correctly, in your `react-router.config.ts` or where you want, add future v8_middleware flag type to true.**
|
|
45
|
-
*
|
|
46
|
-
* ```ts
|
|
47
|
-
* declare module "react-router" {
|
|
48
|
-
* interface Future {
|
|
49
|
-
* v8_middleware: true; // 👈 Enable middleware types
|
|
50
|
-
* }
|
|
51
|
-
* }
|
|
37
|
+
* const context = new RouterContextProvider();
|
|
38
|
+
* context.set(userContext, user);
|
|
39
|
+
* return context;
|
|
52
40
|
* ```
|
|
53
41
|
*/
|
|
54
42
|
getLoadContext?: (c: Context<E>, options: {
|
|
@@ -62,11 +50,11 @@ interface HonoServerOptionsBase<E extends Env> {
|
|
|
62
50
|
*/
|
|
63
51
|
beforeAll?: (app: Hono<E>) => Promise<void> | void;
|
|
64
52
|
}
|
|
65
|
-
interface WithWebsocket<E extends Env> {
|
|
53
|
+
interface WithWebsocket<E extends Env, TUpgradeWebSocket = UpgradeWebSocket> {
|
|
66
54
|
/**
|
|
67
55
|
* Enable WebSockets support in `configure`
|
|
68
56
|
*
|
|
69
|
-
*
|
|
57
|
+
* Development uses the runtime's native implementation or the `@hono/node-server` bridge.
|
|
70
58
|
*
|
|
71
59
|
* Defaults to `false`
|
|
72
60
|
*/
|
|
@@ -77,14 +65,14 @@ interface WithWebsocket<E extends Env> {
|
|
|
77
65
|
* It is applied after the default middleware and before the React Router middleware
|
|
78
66
|
*/
|
|
79
67
|
configure: (app: Hono<E>, options: {
|
|
80
|
-
upgradeWebSocket:
|
|
68
|
+
upgradeWebSocket: TUpgradeWebSocket;
|
|
81
69
|
}) => Promise<void> | void;
|
|
82
70
|
}
|
|
83
71
|
interface WithoutWebsocket<E extends Env> {
|
|
84
72
|
/**
|
|
85
73
|
* Enable WebSockets support in `configure`
|
|
86
74
|
*
|
|
87
|
-
*
|
|
75
|
+
* Development uses the runtime's native implementation or the `@hono/node-server` bridge.
|
|
88
76
|
*
|
|
89
77
|
* Defaults to `false`
|
|
90
78
|
*/
|
package/dist/http.d.ts
CHANGED
package/dist/http.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
function reactRouterRedirect(location) {
|
|
10
10
|
return new Response(new ReadableStream({ start(controller) {
|
|
11
|
-
controller.enqueue(JSON.stringify([
|
|
11
|
+
controller.enqueue(new TextEncoder().encode(JSON.stringify([
|
|
12
12
|
["SingleFetchRedirect", 1],
|
|
13
13
|
{
|
|
14
14
|
_2: 3,
|
|
@@ -26,7 +26,7 @@ function reactRouterRedirect(location) {
|
|
|
26
26
|
"reload",
|
|
27
27
|
true,
|
|
28
28
|
"replace"
|
|
29
|
-
]));
|
|
29
|
+
])));
|
|
30
30
|
controller.close();
|
|
31
31
|
} }), {
|
|
32
32
|
status: 202,
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/react-router-build-request.ts
|
|
2
|
+
/** Whether React Router is rendering a request as part of its build. */
|
|
3
|
+
function isReactRouterBuildRequest() {
|
|
4
|
+
return process.env.IS_RR_BUILD_REQUEST === "yes";
|
|
5
|
+
}
|
|
6
|
+
//#endregion
|
|
7
|
+
export { isReactRouterBuildRequest as t };
|
package/package.json
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "
|
|
4
|
-
"type": "module",
|
|
3
|
+
"version": "4.0.0",
|
|
5
4
|
"description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
"
|
|
5
|
+
"homepage": "https://github.com/rphlmr/react-router-hono-server#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/rphlmr/react-router-hono-server/issues"
|
|
9
8
|
},
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"author": "",
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/rphlmr/react-router-hono-server.git"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"react-router-hono-server": "dist/cli.js"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
10
22
|
"exports": {
|
|
11
23
|
"./node": {
|
|
12
24
|
"import": {
|
|
@@ -65,57 +77,53 @@
|
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
},
|
|
68
|
-
"
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
"type": "git",
|
|
72
|
-
"url": "git+https://github.com/rphlmr/react-router-hono-server.git"
|
|
73
|
-
},
|
|
74
|
-
"bugs": {
|
|
75
|
-
"url": "https://github.com/rphlmr/react-router-hono-server/issues"
|
|
76
|
-
},
|
|
77
|
-
"bin": {
|
|
78
|
-
"react-router-hono-server": "dist/cli.js"
|
|
80
|
+
"publishConfig": {
|
|
81
|
+
"access": "public",
|
|
82
|
+
"provenance": true
|
|
79
83
|
},
|
|
80
|
-
"files": [
|
|
81
|
-
"dist"
|
|
82
|
-
],
|
|
83
|
-
"homepage": "https://github.com/rphlmr/react-router-hono-server#readme",
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"@drizzle-team/brocli": "0.12.0",
|
|
86
|
-
"@hono/node-server": "2.
|
|
87
|
-
"@hono/
|
|
88
|
-
"@hono/vite-dev-server": "0.26.0"
|
|
86
|
+
"@hono/node-server": "2.1.1",
|
|
87
|
+
"@hono/vite-dev-server": "0.26.1"
|
|
89
88
|
},
|
|
90
89
|
"devDependencies": {
|
|
91
|
-
"@
|
|
92
|
-
"@changesets/changelog-github": "
|
|
93
|
-
"@changesets/cli": "
|
|
94
|
-
"@cloudflare/workers-types": "
|
|
95
|
-
"@
|
|
96
|
-
"@types/
|
|
97
|
-
"@types/
|
|
98
|
-
"@
|
|
99
|
-
"
|
|
100
|
-
"
|
|
101
|
-
"
|
|
102
|
-
"
|
|
103
|
-
"
|
|
90
|
+
"@arethetypeswrong/cli": "0.18.5",
|
|
91
|
+
"@changesets/changelog-github": "1.0.0",
|
|
92
|
+
"@changesets/cli": "3.0.0",
|
|
93
|
+
"@cloudflare/workers-types": "5.20260814.1",
|
|
94
|
+
"@playwright/test": "1.62.1",
|
|
95
|
+
"@types/bun": "1.3.14",
|
|
96
|
+
"@types/deno": "2.7.0",
|
|
97
|
+
"@types/node": "24.13.3",
|
|
98
|
+
"@types/react-dom": "19.2.4",
|
|
99
|
+
"@types/ws": "8.18.1",
|
|
100
|
+
"@vitest/coverage-v8": "4.1.10",
|
|
101
|
+
"hono": "4.13.2",
|
|
102
|
+
"npm-run-all": "4.1.5",
|
|
103
|
+
"publint": "0.3.23",
|
|
104
|
+
"react": "19.2.8",
|
|
105
|
+
"react-dom": "19.2.8",
|
|
106
|
+
"typescript": "6.0.3",
|
|
107
|
+
"vite-plus": "0.2.9",
|
|
108
|
+
"ws": "8.21.3"
|
|
104
109
|
},
|
|
105
110
|
"peerDependencies": {
|
|
106
|
-
"@cloudflare/workers-types": "^
|
|
107
|
-
"@
|
|
108
|
-
"@react-router/dev": "^8.0.1",
|
|
111
|
+
"@cloudflare/workers-types": "^5.20260814.1",
|
|
112
|
+
"@react-router/dev": "^8.3.0",
|
|
109
113
|
"@types/react": "^19.2.17",
|
|
110
|
-
"
|
|
111
|
-
"
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
114
|
+
"@types/ws": "^8.18.1",
|
|
115
|
+
"hono": "^4.13.2",
|
|
116
|
+
"miniflare": "^4.20260730.0",
|
|
117
|
+
"react": "^19.2.8",
|
|
118
|
+
"react-dom": "^19.2.8",
|
|
119
|
+
"react-router": "^8.3.0",
|
|
120
|
+
"vite": ">=8.2.1",
|
|
121
|
+
"wrangler": "^4.123.0",
|
|
122
|
+
"ws": "^8.21.3"
|
|
115
123
|
},
|
|
116
124
|
"peerDependenciesMeta": {
|
|
117
|
-
"@
|
|
118
|
-
"optional":
|
|
125
|
+
"@types/ws": {
|
|
126
|
+
"optional": true
|
|
119
127
|
},
|
|
120
128
|
"@cloudflare/workers-types": {
|
|
121
129
|
"optional": true
|
|
@@ -123,28 +131,41 @@
|
|
|
123
131
|
"miniflare": {
|
|
124
132
|
"optional": true
|
|
125
133
|
},
|
|
134
|
+
"ws": {
|
|
135
|
+
"optional": true
|
|
136
|
+
},
|
|
126
137
|
"wrangler": {
|
|
127
138
|
"optional": true
|
|
128
139
|
}
|
|
129
140
|
},
|
|
130
141
|
"engines": {
|
|
131
|
-
"node": ">=24.
|
|
142
|
+
"node": ">=24.19.0"
|
|
132
143
|
},
|
|
133
144
|
"scripts": {
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"build": "tsdown",
|
|
145
|
+
"build": "vp pack",
|
|
146
|
+
"build:pack": "pnpm test:prepare",
|
|
137
147
|
"build:watch": "pnpm run build -- --watch",
|
|
138
|
-
"build:pack": "pnpm pack --pack-destination --out out/react-router-hono-server.tgz",
|
|
139
|
-
"check": "biome check .",
|
|
140
|
-
"check:fix": "biome check --fix .",
|
|
141
|
-
"typecheck": "tsc",
|
|
142
|
-
"validate": "pnpm run check && pnpm run typecheck",
|
|
143
|
-
"clear-all": "rm -rf node_modules pnpm-lock.yaml && find ./examples -type d -name 'node_modules' -exec rm -rf {} + && find ./examples -name 'pnpm-lock.yaml' -exec rm -f {} +",
|
|
144
148
|
"changeset": "changeset",
|
|
145
|
-
"version": "changeset version && biome format --write package.json",
|
|
146
|
-
"release": "changeset publish",
|
|
147
149
|
"changeset:next": "changeset pre enter next",
|
|
148
|
-
"changeset:next:exit": "changeset pre exit"
|
|
150
|
+
"changeset:next:exit": "changeset pre exit",
|
|
151
|
+
"check": "vp check",
|
|
152
|
+
"check:fix": "vp check --fix",
|
|
153
|
+
"clear-all": "rm -rf node_modules pnpm-lock.yaml",
|
|
154
|
+
"release": "changeset publish",
|
|
155
|
+
"test": "vp test run",
|
|
156
|
+
"test:aws": "pnpm test:prepare && vp test run --project runtime tests/integration/aws",
|
|
157
|
+
"test:bun": "pnpm test:prepare && vp test run --project runtime tests/integration/bun",
|
|
158
|
+
"test:cloudflare": "pnpm test:prepare && vp test run --project runtime tests/integration/cloudflare",
|
|
159
|
+
"test:cov": "vp test run --coverage",
|
|
160
|
+
"test:deno": "pnpm test:prepare && vp test run --project runtime tests/integration/deno",
|
|
161
|
+
"test:node": "pnpm test:prepare && vp test run --project runtime tests/integration/node",
|
|
162
|
+
"test:package": "pnpm test:prepare && pnpm test:package:prepared && vp test run --project package",
|
|
163
|
+
"test:package:prepared": "publint out/test-artifacts/*.tgz && attw out/test-artifacts/*.tgz --profile esm-only",
|
|
164
|
+
"test:prepare": "node tests/prepare.ts",
|
|
165
|
+
"test:suite": "pnpm test:prepare && pnpm test:package:prepared && vp test run",
|
|
166
|
+
"test:unit": "vp test run --project unit",
|
|
167
|
+
"typecheck": "tsc",
|
|
168
|
+
"validate": "vp check",
|
|
169
|
+
"version": "changeset version && vp fmt package.json CHANGELOG.md"
|
|
149
170
|
}
|
|
150
171
|
}
|