react-router-hono-server 2.20.0 → 2.22.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 +53 -4
- package/dist/adapters/aws-lambda.d.ts +2 -2
- package/dist/adapters/aws-lambda.js +1 -1
- package/dist/adapters/bun.d.ts +4 -6
- package/dist/adapters/bun.js +1 -1
- package/dist/adapters/cloudflare.d.ts +2 -2
- package/dist/adapters/cloudflare.js +1 -1
- package/dist/adapters/node.d.ts +2 -2
- package/dist/adapters/node.js +1 -1
- package/dist/{chunk-XPXQNPY3.js → chunk-BH64OQMW.js} +4 -4
- package/dist/dev.js +2 -2
- package/dist/{helpers-BKrW-3-B.d.ts → helpers-BXdVojwF.d.ts} +12 -2
- package/dist/middleware.d.ts +1 -1
- package/package.json +21 -20
package/README.md
CHANGED
|
@@ -507,6 +507,19 @@ export type HonoServerOptions<E extends Env = BlankEnv> = {
|
|
|
507
507
|
* }
|
|
508
508
|
* }
|
|
509
509
|
* ```
|
|
510
|
+
*
|
|
511
|
+
* **To make the typing works correctly, in your `react-router.config.ts`, add future v8_middleware flag to true.**
|
|
512
|
+
*
|
|
513
|
+
* ```ts
|
|
514
|
+
* import { defineConfig } from "@react-router/dev";
|
|
515
|
+
*
|
|
516
|
+
* export default defineConfig({
|
|
517
|
+
* future: {
|
|
518
|
+
* v8_middleware: true,
|
|
519
|
+
* },
|
|
520
|
+
* // other config options...
|
|
521
|
+
* });
|
|
522
|
+
* ```
|
|
510
523
|
*/
|
|
511
524
|
getLoadContext?: (
|
|
512
525
|
c: Context,
|
|
@@ -650,7 +663,7 @@ export interface HonoServerOptions<E extends Env = BlankEnv> extends HonoServerO
|
|
|
650
663
|
*
|
|
651
664
|
* {@link https://bun.sh/docs/api/http#start-a-server-bun-serve}
|
|
652
665
|
*/
|
|
653
|
-
customBunServer?: Serve
|
|
666
|
+
customBunServer?: Serve.Options<unknown, string>;
|
|
654
667
|
/**
|
|
655
668
|
* Customize the serve static options
|
|
656
669
|
*/
|
|
@@ -814,16 +827,52 @@ export default createHonoServer({
|
|
|
814
827
|
});
|
|
815
828
|
```
|
|
816
829
|
|
|
817
|
-
### Using React Router Middleware
|
|
830
|
+
### Using React Router Middleware
|
|
818
831
|
You can use React Router middleware with this package.
|
|
819
832
|
|
|
820
833
|
> [!TIP]
|
|
821
834
|
> Check this [example](./examples/node/simple-future-middleware/) to see how to use it.
|
|
822
835
|
|
|
823
836
|
> [!IMPORTANT]
|
|
824
|
-
>
|
|
837
|
+
> **To make the typing works correctly, in your `react-router.config.ts` or where you want, add future v8_middleware flag type to true.**
|
|
838
|
+
>
|
|
839
|
+
> ```ts
|
|
840
|
+
> declare module "react-router" {
|
|
841
|
+
> interface Future {
|
|
842
|
+
> v8_middleware: true; // 👈 Enable middleware types
|
|
843
|
+
> }
|
|
844
|
+
> }
|
|
845
|
+
> ```
|
|
846
|
+
>
|
|
847
|
+
> If you already have a custom `getLoadContext` function, you now have to return an instance of `RouterContextProvider` from it. Check this [example](./examples/node/simple-future-middleware/) for more information.
|
|
848
|
+
>
|
|
849
|
+
> ```ts
|
|
850
|
+
> import { RouterContextProvider, createContext } from "react-router";
|
|
851
|
+
> import { createHonoServer } from "react-router-hono-server/node";
|
|
852
|
+
>
|
|
853
|
+
> console.log("loading server");
|
|
825
854
|
>
|
|
826
|
-
>
|
|
855
|
+
> type GlobalAppContext = {
|
|
856
|
+
> appVersion: string;
|
|
857
|
+
> };
|
|
858
|
+
>
|
|
859
|
+
> export const globalAppContext = createContext<GlobalAppContext>();
|
|
860
|
+
>
|
|
861
|
+
> export default await createHonoServer({
|
|
862
|
+
> getLoadContext(_c, { mode, build }) {
|
|
863
|
+
> const isProductionMode = mode === "production";
|
|
864
|
+
> const context = new RouterContextProvider();
|
|
865
|
+
>
|
|
866
|
+
> context.set(globalAppContext, { appVersion: isProductionMode ? build.assets.version : "dev" });
|
|
867
|
+
>
|
|
868
|
+
> return context;
|
|
869
|
+
> },
|
|
870
|
+
> });
|
|
871
|
+
>```
|
|
872
|
+
|
|
873
|
+
Then, you can use the `use` function from `react-router` to access the context in your loaders and actions.
|
|
874
|
+
|
|
875
|
+
```ts
|
|
827
876
|
|
|
828
877
|
|
|
829
878
|
### Using WebSockets
|
|
@@ -2,8 +2,8 @@ import * as hono_aws_lambda from 'hono/aws-lambda';
|
|
|
2
2
|
import * as hono_types from 'hono/types';
|
|
3
3
|
import { BlankEnv } from 'hono/types';
|
|
4
4
|
import { Env, Hono } from 'hono';
|
|
5
|
-
import { H as HonoServerOptionsBase, W as WithoutWebsocket } from '../helpers-
|
|
6
|
-
export { c as createGetLoadContext } from '../helpers-
|
|
5
|
+
import { H as HonoServerOptionsBase, W as WithoutWebsocket } from '../helpers-BXdVojwF.js';
|
|
6
|
+
export { c as createGetLoadContext } from '../helpers-BXdVojwF.js';
|
|
7
7
|
import 'hono/ws';
|
|
8
8
|
import 'react-router';
|
|
9
9
|
|
package/dist/adapters/bun.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import { Serve
|
|
1
|
+
import { Serve } from 'bun';
|
|
2
2
|
import { Env } from 'hono';
|
|
3
3
|
import { ServeStaticOptions } from 'hono/serve-static';
|
|
4
4
|
import { BlankEnv } from 'hono/types';
|
|
5
|
-
import { H as HonoServerOptionsBase, a as WithWebsocket, W as WithoutWebsocket } from '../helpers-
|
|
6
|
-
export { c as createGetLoadContext } from '../helpers-
|
|
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
7
|
import 'hono/ws';
|
|
8
8
|
import 'react-router';
|
|
9
9
|
|
|
10
|
-
type CustomBunServer = Serve
|
|
11
|
-
websocket?: unknown;
|
|
12
|
-
};
|
|
10
|
+
type CustomBunServer = Serve.Options<unknown, string>;
|
|
13
11
|
interface HonoBunServerOptions<E extends Env = BlankEnv> extends HonoServerOptionsBase<E> {
|
|
14
12
|
/**
|
|
15
13
|
* Customize the bun server
|
package/dist/adapters/bun.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as hono_types from 'hono/types';
|
|
2
2
|
import { BlankEnv } from 'hono/types';
|
|
3
3
|
import { Env, Hono } from 'hono';
|
|
4
|
-
import { H as HonoServerOptionsBase, W as WithoutWebsocket } from '../helpers-
|
|
5
|
-
export { c as createGetLoadContext } from '../helpers-
|
|
4
|
+
import { H as HonoServerOptionsBase, W as WithoutWebsocket } from '../helpers-BXdVojwF.js';
|
|
5
|
+
export { c as createGetLoadContext } from '../helpers-BXdVojwF.js';
|
|
6
6
|
import 'hono/ws';
|
|
7
7
|
import 'react-router';
|
|
8
8
|
|
package/dist/adapters/node.d.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { ServerType } from '@hono/node-server';
|
|
|
3
3
|
import { ServeStaticOptions } from '@hono/node-server/serve-static';
|
|
4
4
|
import { Env, Hono } from 'hono';
|
|
5
5
|
import { BlankEnv } from 'hono/types';
|
|
6
|
-
import { H as HonoServerOptionsBase, a as WithWebsocket, W as WithoutWebsocket } from '../helpers-
|
|
7
|
-
export { c as createGetLoadContext } from '../helpers-
|
|
6
|
+
import { H as HonoServerOptionsBase, a as WithWebsocket, W as WithoutWebsocket } from '../helpers-BXdVojwF.js';
|
|
7
|
+
export { c as createGetLoadContext } from '../helpers-BXdVojwF.js';
|
|
8
8
|
import { ServerOptions, createServer } from 'node:http';
|
|
9
9
|
import { ServerOptions as ServerOptions$2, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
|
|
10
10
|
import { ServerOptions as ServerOptions$1, createServer as createServer$1 } from 'node:https';
|
package/dist/adapters/node.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
// src/helpers.ts
|
|
2
2
|
import { createMiddleware } from "hono/factory";
|
|
3
3
|
var defaultWebSocket = {
|
|
4
|
-
upgradeWebSocket: () => {
|
|
5
|
-
},
|
|
4
|
+
upgradeWebSocket: (() => {
|
|
5
|
+
}),
|
|
6
6
|
injectWebSocket: (server) => server
|
|
7
7
|
};
|
|
8
8
|
async function createWebSocket({ app, enabled }) {
|
|
@@ -43,7 +43,7 @@ function cleanUpgradeListeners(httpServer) {
|
|
|
43
43
|
for (const listener of upgradeListeners) {
|
|
44
44
|
httpServer.removeListener(
|
|
45
45
|
"upgrade",
|
|
46
|
-
/* @ts-
|
|
46
|
+
/* @ts-expect-error - we don't care */
|
|
47
47
|
listener
|
|
48
48
|
);
|
|
49
49
|
}
|
|
@@ -53,7 +53,7 @@ function patchUpgradeListener(httpServer) {
|
|
|
53
53
|
for (const listener of upgradeListeners) {
|
|
54
54
|
httpServer.removeListener(
|
|
55
55
|
"upgrade",
|
|
56
|
-
/* @ts-
|
|
56
|
+
/* @ts-expect-error - we don't care */
|
|
57
57
|
listener
|
|
58
58
|
);
|
|
59
59
|
httpServer.on("upgrade", (request, ...rest) => {
|
package/dist/dev.js
CHANGED
|
@@ -70,7 +70,7 @@ Please add it to your plugins: import { cloudflareDevProxy } from "@react-router
|
|
|
70
70
|
if (reactRouterBuildFile === "index.js") {
|
|
71
71
|
reactRouterBuildFile = "assets/server-build.js";
|
|
72
72
|
}
|
|
73
|
-
let alias =
|
|
73
|
+
let alias = {};
|
|
74
74
|
if (runtime === "cloudflare") {
|
|
75
75
|
const reactVersion = await getReactVersion(pluginConfig);
|
|
76
76
|
alias = {
|
|
@@ -268,7 +268,7 @@ async function getReactVersion(pluginConfig) {
|
|
|
268
268
|
}
|
|
269
269
|
const reactPackage = await import("react");
|
|
270
270
|
const version = reactPackage.default.version || reactPackage.version;
|
|
271
|
-
return Number.parseInt(version.split(".")[0]);
|
|
271
|
+
return Number.parseInt(version.split(".")[0], 10);
|
|
272
272
|
}
|
|
273
273
|
function isCloudflareOptions(options) {
|
|
274
274
|
return options.runtime === "cloudflare";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as hono from 'hono';
|
|
2
2
|
import { Env, Hono, Context } from 'hono';
|
|
3
3
|
import { UpgradeWebSocket } from 'hono/ws';
|
|
4
|
-
import { ServerBuild, UNSAFE_MiddlewareEnabled,
|
|
4
|
+
import { ServerBuild, UNSAFE_MiddlewareEnabled, RouterContextProvider, AppLoadContext } from 'react-router';
|
|
5
5
|
|
|
6
6
|
type ReactRouterHonoServerAppLoadContext = UNSAFE_MiddlewareEnabled extends true
|
|
7
|
-
?
|
|
7
|
+
? RouterContextProvider
|
|
8
8
|
: AppLoadContext;
|
|
9
9
|
|
|
10
10
|
interface HonoServerOptionsBase<E extends Env> {
|
|
@@ -42,6 +42,16 @@ interface HonoServerOptionsBase<E extends Env> {
|
|
|
42
42
|
* }
|
|
43
43
|
* }
|
|
44
44
|
* ```
|
|
45
|
+
*
|
|
46
|
+
* **To make the typing works correctly, in your `react-router.config.ts` or where you want, add future v8_middleware flag type to true.**
|
|
47
|
+
*
|
|
48
|
+
* ```ts
|
|
49
|
+
* declare module "react-router" {
|
|
50
|
+
* interface Future {
|
|
51
|
+
* v8_middleware: true; // 👈 Enable middleware types
|
|
52
|
+
* }
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
45
55
|
*/
|
|
46
56
|
getLoadContext?: (
|
|
47
57
|
c: Context<E>,
|
package/dist/middleware.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ import * as hono from 'hono';
|
|
|
5
5
|
*
|
|
6
6
|
* @param seconds - The number of seconds to cache
|
|
7
7
|
*/
|
|
8
|
-
declare function cache(seconds: number): hono.MiddlewareHandler<any, string, {}>;
|
|
8
|
+
declare function cache(seconds: number): hono.MiddlewareHandler<any, string, {}, Response>;
|
|
9
9
|
|
|
10
10
|
export { cache };
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.22.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": {
|
|
7
|
-
"access": "public"
|
|
7
|
+
"access": "public",
|
|
8
|
+
"provenance": true
|
|
8
9
|
},
|
|
9
10
|
"exports": {
|
|
10
11
|
"./node": {
|
|
@@ -75,32 +76,32 @@
|
|
|
75
76
|
"homepage": "https://github.com/rphlmr/react-router-hono-server#readme",
|
|
76
77
|
"dependencies": {
|
|
77
78
|
"@drizzle-team/brocli": "^0.11.0",
|
|
78
|
-
"@hono/node-server": "^1.
|
|
79
|
+
"@hono/node-server": "^1.19.5",
|
|
79
80
|
"@hono/node-ws": "^1.2.0",
|
|
80
|
-
"@hono/vite-dev-server": "^0.
|
|
81
|
-
"hono": "^4.
|
|
81
|
+
"@hono/vite-dev-server": "^0.23.0",
|
|
82
|
+
"hono": "^4.10.3"
|
|
82
83
|
},
|
|
83
84
|
"devDependencies": {
|
|
84
|
-
"@biomejs/biome": "^
|
|
85
|
-
"@changesets/cli": "^2.29.
|
|
85
|
+
"@biomejs/biome": "^2.3.1",
|
|
86
|
+
"@changesets/cli": "^2.29.7",
|
|
86
87
|
"@cloudflare/workers-types": "^4.20250405.0",
|
|
87
|
-
"@types/bun": "^1.
|
|
88
|
-
"@types/node": "^22.
|
|
89
|
-
"@vitest/coverage-v8": "^
|
|
90
|
-
"lefthook": "^1.
|
|
88
|
+
"@types/bun": "^1.3.1",
|
|
89
|
+
"@types/node": "^22.18.12",
|
|
90
|
+
"@vitest/coverage-v8": "^4.0.4",
|
|
91
|
+
"lefthook": "^1.13.6",
|
|
91
92
|
"npm-run-all": "^4.1.5",
|
|
92
|
-
"tsup": "^8.
|
|
93
|
-
"typescript": "^5.
|
|
94
|
-
"vitest": "^
|
|
93
|
+
"tsup": "^8.5.0",
|
|
94
|
+
"typescript": "^5.9.3",
|
|
95
|
+
"vitest": "^4.0.4"
|
|
95
96
|
},
|
|
96
97
|
"peerDependencies": {
|
|
97
98
|
"@cloudflare/workers-types": "^4.20250317.0",
|
|
98
|
-
"@hono/node-server": "^1.
|
|
99
|
-
"@react-router/dev": "^7.
|
|
100
|
-
"@types/react": "^
|
|
99
|
+
"@hono/node-server": "^1.19.0",
|
|
100
|
+
"@react-router/dev": "^7.9.0",
|
|
101
|
+
"@types/react": "^19.0.0",
|
|
101
102
|
"miniflare": "^3.20241205.0",
|
|
102
|
-
"react-router": "^7.
|
|
103
|
-
"vite": "^
|
|
103
|
+
"react-router": "^7.9.0",
|
|
104
|
+
"vite": "^7.0.0",
|
|
104
105
|
"wrangler": "^4.2.0"
|
|
105
106
|
},
|
|
106
107
|
"peerDependenciesMeta": {
|
|
@@ -118,7 +119,7 @@
|
|
|
118
119
|
}
|
|
119
120
|
},
|
|
120
121
|
"engines": {
|
|
121
|
-
"node": ">=22.
|
|
122
|
+
"node": ">=22.20.0"
|
|
122
123
|
},
|
|
123
124
|
"scripts": {
|
|
124
125
|
"test": "vitest run",
|