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/dev.js
CHANGED
|
@@ -1,302 +1,200 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import path from "path";
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
4
3
|
import honoDevServer from "@hono/vite-dev-server";
|
|
5
4
|
import bunAdapter from "@hono/vite-dev-server/bun";
|
|
6
5
|
import nodeAdapter from "@hono/vite-dev-server/node";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
//#region src/dev.ts
|
|
7
|
+
const REACT_ROUTER_SERVER_BUILD_MODULE_ID = "\0virtual:react-router/server-build";
|
|
8
|
+
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
10
|
function reactRouterHonoServer(options = {}) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
load(id) {
|
|
23
|
-
if (id === VIRTUAL_MODULE_ID) {
|
|
24
|
-
return `
|
|
11
|
+
const runtime = options.runtime || "node";
|
|
12
|
+
let pluginConfig;
|
|
13
|
+
let devServerPlugin;
|
|
14
|
+
return {
|
|
15
|
+
name: "react-router-hono-server",
|
|
16
|
+
enforce: "post",
|
|
17
|
+
resolveId(id) {
|
|
18
|
+
if (id === VIRTUAL_MODULE_ID) return id;
|
|
19
|
+
},
|
|
20
|
+
load(id) {
|
|
21
|
+
if (id === VIRTUAL_MODULE_ID) return `
|
|
25
22
|
// generated by react-router-hono-server/dev
|
|
26
23
|
import { createHonoServer } from "react-router-hono-server/${runtime}";
|
|
27
24
|
|
|
28
25
|
export default await createHonoServer();
|
|
29
26
|
`;
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if (e.code === "ENOENT") {
|
|
150
|
-
console.error("\x1B[31m\nThe server was not built\x1B[0m");
|
|
151
|
-
if (pluginConfig?.flag?.force_react_19) {
|
|
152
|
-
console.error(
|
|
153
|
-
"\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"
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return null;
|
|
158
|
-
});
|
|
159
|
-
if (!serverFile) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
serverFile = serverFile.replace(REACT_ROUTER_EXPORT, "");
|
|
163
|
-
if (await getReactVersion(pluginConfig) >= 19) {
|
|
164
|
-
serverFile = serverFile.replace(/react-dom\/server\.browser/g, "react-dom/server.edge");
|
|
165
|
-
}
|
|
166
|
-
await fs.promises.writeFile(buildPath, serverFile);
|
|
167
|
-
console.log("\x1B[32mAll done!\x1B[0m");
|
|
168
|
-
},
|
|
169
|
-
async configureServer(server) {
|
|
170
|
-
globalThis.__viteDevServer = server;
|
|
171
|
-
if (!pluginConfig) {
|
|
172
|
-
return;
|
|
173
|
-
}
|
|
174
|
-
if (devServerPlugin) {
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
let adapter = nodeAdapter;
|
|
178
|
-
if (runtime === "bun") {
|
|
179
|
-
adapter = bunAdapter;
|
|
180
|
-
}
|
|
181
|
-
if (runtime === "cloudflare") {
|
|
182
|
-
const { cloudflareAdapter } = await import("@hono/vite-dev-server/cloudflare");
|
|
183
|
-
adapter = cloudflareAdapter;
|
|
184
|
-
}
|
|
185
|
-
if (runtime === "deno") {
|
|
186
|
-
adapter = () => {
|
|
187
|
-
if (typeof globalThis.navigator === "undefined") {
|
|
188
|
-
globalThis.navigator = {
|
|
189
|
-
userAgent: "Deno"
|
|
190
|
-
};
|
|
191
|
-
} else {
|
|
192
|
-
Object.defineProperty(globalThis.navigator, "userAgent", {
|
|
193
|
-
value: "Deno",
|
|
194
|
-
writable: false
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
return {
|
|
198
|
-
env: Deno.env.toObject()
|
|
199
|
-
};
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
devServerPlugin = honoDevServer({
|
|
203
|
-
adapter,
|
|
204
|
-
injectClientScript: false,
|
|
205
|
-
entry: pluginConfig.serverEntryPoint,
|
|
206
|
-
export: options.dev?.export || "default",
|
|
207
|
-
exclude: [
|
|
208
|
-
new RegExp(
|
|
209
|
-
`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/")}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`
|
|
210
|
-
),
|
|
211
|
-
new RegExp(
|
|
212
|
-
`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/").split("/")[0]}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`
|
|
213
|
-
),
|
|
214
|
-
/\?import(\?.*)?$/,
|
|
215
|
-
/^\/@.+$/,
|
|
216
|
-
/^\/node_modules\/.*/,
|
|
217
|
-
`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/")}/**/.*/**)`,
|
|
218
|
-
`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/").split("/")[0]}/**/.*/**)`,
|
|
219
|
-
...pluginConfig.dev?.exclude || []
|
|
220
|
-
]
|
|
221
|
-
});
|
|
222
|
-
server.middlewares.use((req, _res, next) => {
|
|
223
|
-
req.rawHeaders.push("x-remote-address", req.socket.remoteAddress || "unknown");
|
|
224
|
-
req.rawHeaders.push("x-remote-port", String(req.socket.remotePort || "unknown"));
|
|
225
|
-
req.rawHeaders.push("x-remote-family", req.socket.remoteFamily || "unknown");
|
|
226
|
-
next();
|
|
227
|
-
});
|
|
228
|
-
if (typeof devServerPlugin.configureServer === "function") {
|
|
229
|
-
devServerPlugin.configureServer(server);
|
|
230
|
-
} else {
|
|
231
|
-
console.error("Dev server plugin configureServer hook is not a function. This is likely a bug, I guess \u{1F605}\n");
|
|
232
|
-
throw new Error("Cannot apply dev server plugin configureServer hook");
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
};
|
|
27
|
+
},
|
|
28
|
+
async config(config, env) {
|
|
29
|
+
pluginConfig = resolvePluginConfig(config, options);
|
|
30
|
+
if (!pluginConfig) return;
|
|
31
|
+
const serverEntryPoint = pluginConfig.serverEntryPoint;
|
|
32
|
+
if (env.mode === "development" && runtime === "cloudflare" && !config.plugins?.find((p) => p && "name" in p && p.name === "react-router-cloudflare-vite-dev-proxy")) console.warn(`\x1b[31mMissing cloudflareDevProxy() in your vite.config.ts.\nPlease add it to your plugins: import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare";\x1b[0m\n`);
|
|
33
|
+
const baseConfig = {
|
|
34
|
+
define: {
|
|
35
|
+
"import.meta.env.REACT_ROUTER_HONO_SERVER_BUILD_DIRECTORY": JSON.stringify(pluginConfig.buildDirectory),
|
|
36
|
+
"import.meta.env.REACT_ROUTER_HONO_SERVER_ASSETS_DIR": JSON.stringify(pluginConfig.assetsDir),
|
|
37
|
+
"import.meta.env.REACT_ROUTER_HONO_SERVER_RUNTIME": JSON.stringify(runtime),
|
|
38
|
+
"import.meta.env.REACT_ROUTER_HONO_SERVER_BASENAME": JSON.stringify(pluginConfig.basename)
|
|
39
|
+
},
|
|
40
|
+
ssr: {
|
|
41
|
+
target: runtime === "cloudflare" ? "webworker" : void 0,
|
|
42
|
+
noExternal: ["react-router-hono-server"],
|
|
43
|
+
external: ["@hono/node-ws"],
|
|
44
|
+
optimizeDeps: runtime === "bun" ? {
|
|
45
|
+
include: ["react-dom/server"],
|
|
46
|
+
exclude: ["react"]
|
|
47
|
+
} : void 0
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
let reactRouterBuildFile = pluginConfig.serverBuildFile;
|
|
51
|
+
if (reactRouterBuildFile === "index.js") reactRouterBuildFile = "assets/server-build.js";
|
|
52
|
+
const resolve = {};
|
|
53
|
+
if (runtime === "cloudflare") resolve.alias = { "react-dom/server": await getReactVersion(pluginConfig) >= 19 ? "react-dom/server.edge" : "react-dom/server.browser" };
|
|
54
|
+
if (runtime === "bun") resolve.alias = { "react-dom/server": "react-dom/server.node" };
|
|
55
|
+
if (runtime === "deno") resolve.alias = { "react-dom/server": "react-dom/server.node" };
|
|
56
|
+
const ssrConfig = {
|
|
57
|
+
resolve,
|
|
58
|
+
build: { rollupOptions: {
|
|
59
|
+
input: serverEntryPoint,
|
|
60
|
+
output: {
|
|
61
|
+
entryFileNames: (chunk) => {
|
|
62
|
+
chunk.facadeModuleId = REACT_ROUTER_SERVER_BUILD_MODULE_ID;
|
|
63
|
+
return "index.js";
|
|
64
|
+
},
|
|
65
|
+
chunkFileNames: (chunk) => {
|
|
66
|
+
if (chunk.name === "server-build") return reactRouterBuildFile;
|
|
67
|
+
return "assets/[name]-[hash].js";
|
|
68
|
+
},
|
|
69
|
+
manualChunks: runtime !== "cloudflare" ? (id, meta) => {
|
|
70
|
+
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
|
|
73
|
+
}
|
|
74
|
+
} }
|
|
75
|
+
};
|
|
76
|
+
return {
|
|
77
|
+
...baseConfig,
|
|
78
|
+
resolve,
|
|
79
|
+
environments: { ssr: ssrConfig }
|
|
80
|
+
};
|
|
81
|
+
},
|
|
82
|
+
async closeBundle() {
|
|
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) {
|
|
100
|
+
globalThis.__viteDevServer = server;
|
|
101
|
+
if (!pluginConfig) return;
|
|
102
|
+
if (devServerPlugin) return;
|
|
103
|
+
let adapter = nodeAdapter;
|
|
104
|
+
if (runtime === "bun") adapter = bunAdapter;
|
|
105
|
+
if (runtime === "cloudflare") {
|
|
106
|
+
const { cloudflareAdapter } = await import("@hono/vite-dev-server/cloudflare");
|
|
107
|
+
adapter = cloudflareAdapter;
|
|
108
|
+
}
|
|
109
|
+
if (runtime === "deno") adapter = () => {
|
|
110
|
+
if (typeof globalThis.navigator === "undefined") globalThis.navigator = { userAgent: "Deno" };
|
|
111
|
+
else Object.defineProperty(globalThis.navigator, "userAgent", {
|
|
112
|
+
value: "Deno",
|
|
113
|
+
writable: false
|
|
114
|
+
});
|
|
115
|
+
return { env: Deno.env.toObject() };
|
|
116
|
+
};
|
|
117
|
+
devServerPlugin = honoDevServer({
|
|
118
|
+
adapter,
|
|
119
|
+
injectClientScript: false,
|
|
120
|
+
entry: pluginConfig.serverEntryPoint,
|
|
121
|
+
export: options.dev?.export || "default",
|
|
122
|
+
exclude: [
|
|
123
|
+
new RegExp(`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/")}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`),
|
|
124
|
+
new RegExp(`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replaceAll(/[/\\]+/g, "/").split("/")[0]}\\/)((?!.*\\.data(\\?|$)).*\\..*(\\?.*)?$)`),
|
|
125
|
+
/\?import(\?.*)?$/,
|
|
126
|
+
/^\/@.+$/,
|
|
127
|
+
/^\/node_modules\/.*/,
|
|
128
|
+
`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/")}/**/.*/**)`,
|
|
129
|
+
`^(?=\\/${pluginConfig.appDirectory.replace(/^[/\\]+|[/\\]+$/g, "").replace(/[/\\]+/g, "/").split("/")[0]}/**/.*/**)`,
|
|
130
|
+
...pluginConfig.dev?.exclude || []
|
|
131
|
+
]
|
|
132
|
+
});
|
|
133
|
+
server.middlewares.use((req, _res, next) => {
|
|
134
|
+
req.rawHeaders.push("x-remote-address", req.socket.remoteAddress || "unknown");
|
|
135
|
+
req.rawHeaders.push("x-remote-port", String(req.socket.remotePort || "unknown"));
|
|
136
|
+
req.rawHeaders.push("x-remote-family", req.socket.remoteFamily || "unknown");
|
|
137
|
+
next();
|
|
138
|
+
});
|
|
139
|
+
if (typeof devServerPlugin.configureServer === "function") devServerPlugin.configureServer(server);
|
|
140
|
+
else {
|
|
141
|
+
console.error("Dev server plugin configureServer hook is not a function. This is likely a bug, I guess 😅\n");
|
|
142
|
+
throw new Error("Cannot apply dev server plugin configureServer hook");
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
236
146
|
}
|
|
237
147
|
function resolvePluginConfig(config, options) {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
flag: isCloudflareOptions(options) ? options.flag : {}
|
|
262
|
-
};
|
|
148
|
+
if (!("__reactRouterPluginContext" in config)) return null;
|
|
149
|
+
const { reactRouterConfig, environmentBuildContext, rootDirectory } = config.__reactRouterPluginContext;
|
|
150
|
+
const buildDirectory = path.relative(rootDirectory, reactRouterConfig.buildDirectory);
|
|
151
|
+
const appDirectory = path.relative(rootDirectory, reactRouterConfig.appDirectory);
|
|
152
|
+
const isSsrBuild = environmentBuildContext?.name === "ssr";
|
|
153
|
+
const assetsDir = config.build?.assetsDir || "assets";
|
|
154
|
+
const serverEntryPoint = options.serverEntryPoint || findDefaultServerEntry(appDirectory);
|
|
155
|
+
const serverBuildFile = reactRouterConfig.serverBuildFile;
|
|
156
|
+
const basename = reactRouterConfig.basename;
|
|
157
|
+
const future = reactRouterConfig.future;
|
|
158
|
+
return {
|
|
159
|
+
rootDirectory,
|
|
160
|
+
buildDirectory,
|
|
161
|
+
appDirectory,
|
|
162
|
+
isSsrBuild,
|
|
163
|
+
assetsDir,
|
|
164
|
+
serverEntryPoint,
|
|
165
|
+
dev: options.dev,
|
|
166
|
+
serverBuildFile,
|
|
167
|
+
basename,
|
|
168
|
+
future,
|
|
169
|
+
flag: isCloudflareOptions(options) ? options.flag : {}
|
|
170
|
+
};
|
|
263
171
|
}
|
|
264
|
-
|
|
172
|
+
let warned = false;
|
|
265
173
|
function findDefaultServerEntry(appDirectory) {
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
console.warn(
|
|
276
|
-
`\x1B[33mNo server entry point found.
|
|
277
|
-
Will use a virtual module (${VIRTUAL_MODULE_ID}) with a default Hono server.
|
|
278
|
-
|
|
279
|
-
To customize the server, create one of the following files:
|
|
280
|
-
- ${fileWay} (npx react-router-hono-server reveal file)
|
|
281
|
-
- ${folderWay} (npx react-router-hono-server reveal folder)
|
|
282
|
-
You can also set the \`serverEntryPoint\` option in the reactRouterHonoServer plugin for more control.\x1B[0m
|
|
283
|
-
`
|
|
284
|
-
);
|
|
285
|
-
warned = true;
|
|
286
|
-
}
|
|
287
|
-
return VIRTUAL_MODULE_ID;
|
|
174
|
+
const fileWay = `${appDirectory}/server.ts`;
|
|
175
|
+
const folderWay = `${appDirectory}/server/index.ts`;
|
|
176
|
+
if (fs.existsSync(fileWay)) return fileWay;
|
|
177
|
+
if (fs.existsSync(folderWay)) return folderWay;
|
|
178
|
+
if (!warned) {
|
|
179
|
+
console.warn(`\x1b[33mNo server entry point found.\nWill use a virtual module (${VIRTUAL_MODULE_ID}) with a default Hono server.\n\nTo customize the server, create one of the following files:\n - ${fileWay} (npx react-router-hono-server reveal file)\n - ${folderWay} (npx react-router-hono-server reveal folder)\nYou can also set the \`serverEntryPoint\` option in the reactRouterHonoServer plugin for more control.\x1b[0m\n`);
|
|
180
|
+
warned = true;
|
|
181
|
+
}
|
|
182
|
+
return VIRTUAL_MODULE_ID;
|
|
288
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Retrieves the major React version from node_modules
|
|
186
|
+
*/
|
|
289
187
|
async function getReactVersion(pluginConfig) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
const version = reactPackage.default.version || reactPackage.version;
|
|
295
|
-
return Number.parseInt(version.split(".")[0], 10);
|
|
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);
|
|
296
192
|
}
|
|
193
|
+
/**
|
|
194
|
+
* Type guard to check if options is the Cloudflare variant
|
|
195
|
+
*/
|
|
297
196
|
function isCloudflareOptions(options) {
|
|
298
|
-
|
|
197
|
+
return options.runtime === "cloudflare";
|
|
299
198
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
};
|
|
199
|
+
//#endregion
|
|
200
|
+
export { reactRouterHonoServer };
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { Env, Hono
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
type ReactRouterHonoServerAppLoadContext = UNSAFE_MiddlewareEnabled extends true
|
|
7
|
-
? RouterContextProvider
|
|
8
|
-
: AppLoadContext;
|
|
1
|
+
import { ServerType } from "@hono/node-server";
|
|
2
|
+
import { Context, Env, Hono } from "hono";
|
|
3
|
+
import { AppLoadContext, RouterContextProvider, ServerBuild, UNSAFE_MiddlewareEnabled } from "react-router";
|
|
4
|
+
import { UpgradeWebSocket } from "hono/ws";
|
|
9
5
|
|
|
6
|
+
//#region src/types/hono-server-options-base.d.ts
|
|
7
|
+
type ReactRouterHonoServerAppLoadContext = UNSAFE_MiddlewareEnabled extends true ? RouterContextProvider : AppLoadContext;
|
|
10
8
|
interface HonoServerOptionsBase<E extends Env> {
|
|
11
9
|
/**
|
|
12
10
|
* The base Hono app to use as a replacement for the default one created automatically
|
|
@@ -53,13 +51,10 @@ interface HonoServerOptionsBase<E extends Env> {
|
|
|
53
51
|
* }
|
|
54
52
|
* ```
|
|
55
53
|
*/
|
|
56
|
-
getLoadContext?: (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
mode: string;
|
|
61
|
-
}
|
|
62
|
-
) => Promise<ReactRouterHonoServerAppLoadContext> | ReactRouterHonoServerAppLoadContext;
|
|
54
|
+
getLoadContext?: (c: Context<E>, options: {
|
|
55
|
+
build: ServerBuild;
|
|
56
|
+
mode: string;
|
|
57
|
+
}) => Promise<ReactRouterHonoServerAppLoadContext> | ReactRouterHonoServerAppLoadContext;
|
|
63
58
|
/**
|
|
64
59
|
* Hook to add middleware that runs before any built-in middleware, including assets serving.
|
|
65
60
|
*
|
|
@@ -67,7 +62,6 @@ interface HonoServerOptionsBase<E extends Env> {
|
|
|
67
62
|
*/
|
|
68
63
|
beforeAll?: (app: Hono<E>) => Promise<void> | void;
|
|
69
64
|
}
|
|
70
|
-
|
|
71
65
|
interface WithWebsocket<E extends Env> {
|
|
72
66
|
/**
|
|
73
67
|
* Enable WebSockets support in `configure`
|
|
@@ -82,9 +76,10 @@ interface WithWebsocket<E extends Env> {
|
|
|
82
76
|
*
|
|
83
77
|
* It is applied after the default middleware and before the React Router middleware
|
|
84
78
|
*/
|
|
85
|
-
configure: (app: Hono<E>, options: {
|
|
79
|
+
configure: (app: Hono<E>, options: {
|
|
80
|
+
upgradeWebSocket: UpgradeWebSocket;
|
|
81
|
+
}) => Promise<void> | void;
|
|
86
82
|
}
|
|
87
|
-
|
|
88
83
|
interface WithoutWebsocket<E extends Env> {
|
|
89
84
|
/**
|
|
90
85
|
* Enable WebSockets support in `configure`
|
|
@@ -101,13 +96,14 @@ interface WithoutWebsocket<E extends Env> {
|
|
|
101
96
|
*/
|
|
102
97
|
configure?: (app: Hono<E>) => Promise<void> | void;
|
|
103
98
|
}
|
|
104
|
-
|
|
99
|
+
//#endregion
|
|
100
|
+
//#region src/helpers.d.ts
|
|
105
101
|
/**
|
|
106
102
|
* Helper to create a getLoadContext function fully typed
|
|
107
103
|
*/
|
|
108
|
-
declare function createGetLoadContext(getLoadContext: HonoServerOptionsBase<Env>["getLoadContext"]): ((c: hono.Context<Env, any, {}>, options: {
|
|
109
|
-
|
|
110
|
-
|
|
104
|
+
declare function createGetLoadContext(getLoadContext: HonoServerOptionsBase<Env>["getLoadContext"]): ((c: import("hono").Context<Env, any, {}>, options: {
|
|
105
|
+
build: ServerBuild;
|
|
106
|
+
mode: string;
|
|
111
107
|
}) => Promise<ReactRouterHonoServerAppLoadContext> | ReactRouterHonoServerAppLoadContext) | undefined;
|
|
112
|
-
|
|
113
|
-
export {
|
|
108
|
+
//#endregion
|
|
109
|
+
export { WithoutWebsocket as i, HonoServerOptionsBase as n, WithWebsocket as r, createGetLoadContext as t };
|