react-router-hono-server 1.2.0 → 2.1.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 +383 -102
- package/dist/adapters/bun.d.mts +107 -0
- package/dist/adapters/bun.mjs +57 -0
- package/dist/adapters/cloudflare.d.mts +17 -0
- package/dist/adapters/cloudflare.mjs +38 -0
- package/dist/adapters/node.d.mts +57 -0
- package/dist/adapters/node.mjs +66 -0
- package/dist/chunk-ENK5WJB4.mjs +18 -0
- package/dist/cli.mjs +45 -0
- package/dist/dev.d.mts +22 -25
- package/dist/dev.mjs +149 -23
- package/dist/hono-server-options-base.d-DChVrA1u.d.mts +54 -0
- package/dist/middleware.d.mts +10 -0
- package/dist/middleware.mjs +6 -0
- package/package.json +44 -27
- package/dist/node.d.mts +0 -114
- package/dist/node.mjs +0 -78
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { Env, Hono, Context } from 'hono';
|
|
2
|
+
import { HonoOptions } from 'hono/hono-base';
|
|
3
|
+
import { BlankEnv } from 'hono/types';
|
|
4
|
+
import { ServerBuild, AppLoadContext } from 'react-router';
|
|
5
|
+
|
|
6
|
+
interface HonoServerOptionsBase<E extends Env = BlankEnv> {
|
|
7
|
+
/**
|
|
8
|
+
* Enable the default logger
|
|
9
|
+
*
|
|
10
|
+
* Defaults to `true`
|
|
11
|
+
*/
|
|
12
|
+
defaultLogger?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The port to start the server on
|
|
15
|
+
*
|
|
16
|
+
* Defaults to `process.env.PORT || 3000`
|
|
17
|
+
*/
|
|
18
|
+
port?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Customize the Hono server, for example, adding middleware
|
|
21
|
+
*
|
|
22
|
+
* It is applied after the default middleware and before the React Router middleware
|
|
23
|
+
*/
|
|
24
|
+
configure?: <E extends Env = BlankEnv>(server: Hono<E>) => Promise<void> | void;
|
|
25
|
+
/**
|
|
26
|
+
* Augment the React Router AppLoadContext
|
|
27
|
+
*
|
|
28
|
+
* Don't forget to declare the AppLoadContext in your app, next to where you create the Hono server
|
|
29
|
+
*
|
|
30
|
+
* ```ts
|
|
31
|
+
* declare module "react-router" {
|
|
32
|
+
* interface AppLoadContext {
|
|
33
|
+
* // Add your custom context here
|
|
34
|
+
* whatever: string;
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
getLoadContext?: (
|
|
40
|
+
c: Context,
|
|
41
|
+
options: {
|
|
42
|
+
build: ServerBuild;
|
|
43
|
+
mode: string;
|
|
44
|
+
}
|
|
45
|
+
) => Promise<AppLoadContext> | AppLoadContext;
|
|
46
|
+
/**
|
|
47
|
+
* Hono constructor options
|
|
48
|
+
*
|
|
49
|
+
* {@link HonoOptions}
|
|
50
|
+
*/
|
|
51
|
+
honoOptions?: HonoOptions<E>;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type { HonoServerOptionsBase as H };
|
package/package.json
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.1.0",
|
|
4
|
+
"description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./node": {
|
|
7
7
|
"import": {
|
|
8
|
-
"import": "./dist/node.mjs",
|
|
9
|
-
"types": "./dist/node.d.mts",
|
|
10
|
-
"default": "./dist/node.mjs"
|
|
8
|
+
"import": "./dist/adapters/node.mjs",
|
|
9
|
+
"types": "./dist/adapters/node.d.mts",
|
|
10
|
+
"default": "./dist/adapters/node.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"./bun": {
|
|
14
|
+
"import": {
|
|
15
|
+
"import": "./dist/adapters/bun.mjs",
|
|
16
|
+
"types": "./dist/adapters/bun.d.mts",
|
|
17
|
+
"default": "./dist/adapters/bun.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"./cloudflare": {
|
|
21
|
+
"import": {
|
|
22
|
+
"import": "./dist/adapters/cloudflare.mjs",
|
|
23
|
+
"types": "./dist/adapters/cloudflare.d.mts",
|
|
24
|
+
"default": "./dist/adapters/cloudflare.mjs"
|
|
11
25
|
}
|
|
12
26
|
},
|
|
13
27
|
"./dev": {
|
|
@@ -28,11 +42,10 @@
|
|
|
28
42
|
"scripts": {
|
|
29
43
|
"test": "vitest run",
|
|
30
44
|
"test:cov": "vitest run --coverage",
|
|
31
|
-
"build": "tsup
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"dev": "npm-run-all -s build:dev -p remix:dev build:dev:watch",
|
|
45
|
+
"build": "tsup",
|
|
46
|
+
"build:watch": "npm run build -- --watch",
|
|
47
|
+
"example:dev": "npm run dev -w react-router-example",
|
|
48
|
+
"dev": "npm-run-all -s build -p example:dev build:watch",
|
|
36
49
|
"prepublishOnly": "npm run build",
|
|
37
50
|
"check": "biome check .",
|
|
38
51
|
"check:fix": "biome check --fix .",
|
|
@@ -48,31 +61,35 @@
|
|
|
48
61
|
"bugs": {
|
|
49
62
|
"url": "https://github.com/rphlmr/react-router-hono-server/issues"
|
|
50
63
|
},
|
|
64
|
+
"bin": {
|
|
65
|
+
"react-router-hono-server": "dist/cli.mjs"
|
|
66
|
+
},
|
|
51
67
|
"files": ["dist"],
|
|
52
68
|
"workspaces": [".", "examples/*"],
|
|
53
69
|
"homepage": "https://github.com/rphlmr/react-router-hono-server#readme",
|
|
54
70
|
"dependencies": {
|
|
55
|
-
"@
|
|
56
|
-
"@hono/
|
|
57
|
-
"hono": "^
|
|
58
|
-
"
|
|
71
|
+
"@drizzle-team/brocli": "^0.11.0",
|
|
72
|
+
"@hono/node-server": "^1.13.7",
|
|
73
|
+
"@hono/vite-dev-server": "^0.17.0",
|
|
74
|
+
"hono": "^4.6.11"
|
|
59
75
|
},
|
|
60
76
|
"devDependencies": {
|
|
61
|
-
"@biomejs/biome": "^1.
|
|
62
|
-
"@
|
|
63
|
-
"@types/node": "^
|
|
64
|
-
"@vitest/coverage-v8": "^1.5
|
|
65
|
-
"
|
|
66
|
-
"
|
|
77
|
+
"@biomejs/biome": "^1.9.4",
|
|
78
|
+
"@types/bun": "^1.1.14",
|
|
79
|
+
"@types/node": "^22.9.3",
|
|
80
|
+
"@vitest/coverage-v8": "^2.1.5",
|
|
81
|
+
"lefthook": "^1.8.4",
|
|
82
|
+
"miniflare": "^3.20241106.1",
|
|
67
83
|
"npm-run-all": "^4.1.5",
|
|
68
|
-
"tsup": "^8.
|
|
69
|
-
"typescript": "^5.
|
|
70
|
-
"vitest": "^1.5
|
|
84
|
+
"tsup": "^8.3.5",
|
|
85
|
+
"typescript": "^5.7.2",
|
|
86
|
+
"vitest": "^2.1.5"
|
|
71
87
|
},
|
|
72
88
|
"peerDependencies": {
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
|
|
76
|
-
|
|
89
|
+
"react-router": "^7.0.1",
|
|
90
|
+
"vite": "^5.4.0"
|
|
91
|
+
},
|
|
92
|
+
"engines": {
|
|
93
|
+
"node": ">=20.0.0"
|
|
77
94
|
}
|
|
78
95
|
}
|
package/dist/node.d.mts
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import * as hono_types from 'hono/types';
|
|
2
|
-
import { BlankEnv } from 'hono/types';
|
|
3
|
-
import { ServerOptions, createServer } from 'node:http';
|
|
4
|
-
import { ServerOptions as ServerOptions$2, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
|
|
5
|
-
import { ServerOptions as ServerOptions$1, createServer as createServer$1 } from 'node:https';
|
|
6
|
-
import { AddressInfo } from 'node:net';
|
|
7
|
-
import { AppLoadContext } from '@remix-run/node';
|
|
8
|
-
import { Env, Hono, Context } from 'hono';
|
|
9
|
-
import { HonoOptions } from 'hono/hono-base';
|
|
10
|
-
import { RemixMiddlewareOptions } from 'remix-hono/handler';
|
|
11
|
-
|
|
12
|
-
type createHttpOptions = {
|
|
13
|
-
serverOptions?: ServerOptions;
|
|
14
|
-
createServer?: typeof createServer;
|
|
15
|
-
};
|
|
16
|
-
type createHttpsOptions = {
|
|
17
|
-
serverOptions?: ServerOptions$1;
|
|
18
|
-
createServer?: typeof createServer$1;
|
|
19
|
-
};
|
|
20
|
-
type createHttp2Options = {
|
|
21
|
-
serverOptions?: ServerOptions$2;
|
|
22
|
-
createServer?: typeof createServer$2;
|
|
23
|
-
};
|
|
24
|
-
type createSecureHttp2Options = {
|
|
25
|
-
serverOptions?: SecureServerOptions;
|
|
26
|
-
createServer?: typeof createSecureServer;
|
|
27
|
-
};
|
|
28
|
-
type CreateNodeServerOptions = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
|
29
|
-
type HonoServerOptions<E extends Env = BlankEnv> = {
|
|
30
|
-
/**
|
|
31
|
-
* Enable the default logger
|
|
32
|
-
*
|
|
33
|
-
* Defaults to `true`
|
|
34
|
-
*/
|
|
35
|
-
defaultLogger?: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* The port to start the server on
|
|
38
|
-
*
|
|
39
|
-
* Defaults to `process.env.PORT || 3000`
|
|
40
|
-
*/
|
|
41
|
-
port?: number;
|
|
42
|
-
/**
|
|
43
|
-
* The directory where the server build files are located (defined in vite.config)
|
|
44
|
-
*
|
|
45
|
-
* Defaults to `build`
|
|
46
|
-
*
|
|
47
|
-
* See https://remix.run/docs/en/main/file-conventions/vite-config#builddirectory
|
|
48
|
-
*/
|
|
49
|
-
buildDirectory?: string;
|
|
50
|
-
/**
|
|
51
|
-
* The file name of the server build file (defined in vite.config)
|
|
52
|
-
*
|
|
53
|
-
* Defaults to `index.js`
|
|
54
|
-
*
|
|
55
|
-
* See https://remix.run/docs/en/main/file-conventions/vite-config#serverbuildfile
|
|
56
|
-
*/
|
|
57
|
-
serverBuildFile?: `${string}.js` | `${string}.mjs` | `${string}.cjs`;
|
|
58
|
-
/**
|
|
59
|
-
* The directory where the assets are located (defined in vite.config, build.assetsDir)
|
|
60
|
-
*
|
|
61
|
-
* Defaults to `assets`
|
|
62
|
-
*
|
|
63
|
-
* See https://vitejs.dev/config/build-options#build-assetsdir
|
|
64
|
-
*/
|
|
65
|
-
assetsDir?: string;
|
|
66
|
-
/**
|
|
67
|
-
* Customize the Hono server, for example, adding middleware
|
|
68
|
-
*
|
|
69
|
-
* It is applied after the default middleware and before the remix middleware
|
|
70
|
-
*/
|
|
71
|
-
configure?: <E extends Env = BlankEnv>(server: Hono<E>) => Promise<void> | void;
|
|
72
|
-
/**
|
|
73
|
-
* Augment the Remix AppLoadContext
|
|
74
|
-
*
|
|
75
|
-
* Don't forget to declare the AppLoadContext in your app, next to where you create the Hono server
|
|
76
|
-
*
|
|
77
|
-
* ```ts
|
|
78
|
-
* declare module "@remix-run/node" {
|
|
79
|
-
* interface AppLoadContext {
|
|
80
|
-
* // Add your custom context here
|
|
81
|
-
* }
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
getLoadContext?: (c: Context, options: Pick<RemixMiddlewareOptions, "build" | "mode">) => Promise<AppLoadContext> | AppLoadContext;
|
|
86
|
-
/**
|
|
87
|
-
* Listening listener (production mode only)
|
|
88
|
-
*
|
|
89
|
-
* It is called when the server is listening
|
|
90
|
-
*
|
|
91
|
-
* Defaults log the port
|
|
92
|
-
*/
|
|
93
|
-
listeningListener?: (info: AddressInfo) => void;
|
|
94
|
-
/**
|
|
95
|
-
* Hono constructor options
|
|
96
|
-
*
|
|
97
|
-
* {@link HonoOptions}
|
|
98
|
-
*/
|
|
99
|
-
honoOptions?: HonoOptions<E>;
|
|
100
|
-
/**
|
|
101
|
-
* Customize the node server (ex: using http2)
|
|
102
|
-
*
|
|
103
|
-
* {@link https://hono.dev/docs/getting-started/nodejs#http2}
|
|
104
|
-
*/
|
|
105
|
-
customNodeServer?: CreateNodeServerOptions;
|
|
106
|
-
};
|
|
107
|
-
/**
|
|
108
|
-
* Create a Hono server
|
|
109
|
-
*
|
|
110
|
-
* @param config {@link HonoServerOptions} - The configuration options for the server
|
|
111
|
-
*/
|
|
112
|
-
declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, hono_types.BlankSchema, "/">>;
|
|
113
|
-
|
|
114
|
-
export { type HonoServerOptions, createHonoServer };
|
package/dist/node.mjs
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
// src/node.ts
|
|
2
|
-
import c from "node:path";
|
|
3
|
-
import O from "node:url";
|
|
4
|
-
import { serve as g } from "@hono/node-server";
|
|
5
|
-
import { serveStatic as v } from "@hono/node-server/serve-static";
|
|
6
|
-
import { Hono as y } from "hono";
|
|
7
|
-
import { logger as E } from "hono/logger";
|
|
8
|
-
import { remix as x } from "remix-hono/handler";
|
|
9
|
-
|
|
10
|
-
// src/dev-build.ts
|
|
11
|
-
var S = process.env.NODE_ENV === "production" ? void 0 : await import("vite").then(
|
|
12
|
-
(r) => r.createServer({
|
|
13
|
-
server: { middlewareMode: !0 },
|
|
14
|
-
appType: "custom"
|
|
15
|
-
})
|
|
16
|
-
);
|
|
17
|
-
async function a() {
|
|
18
|
-
return S?.ssrLoadModule("virtual:remix/server-build");
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// src/middleware.ts
|
|
22
|
-
import { createMiddleware as f } from "hono/factory";
|
|
23
|
-
function i(r) {
|
|
24
|
-
return f(async (e, o) => {
|
|
25
|
-
if (!e.req.path.match(/\.[a-zA-Z0-9]+$/) || e.req.path.endsWith(".data"))
|
|
26
|
-
return o();
|
|
27
|
-
await o(), e.res.ok && e.res.headers.set("cache-control", `public, max-age=${r}`);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// src/node.ts
|
|
32
|
-
var h = {
|
|
33
|
-
defaultLogger: !0,
|
|
34
|
-
port: Number(process.env.PORT) || 3e3,
|
|
35
|
-
buildDirectory: "build",
|
|
36
|
-
serverBuildFile: "index.js",
|
|
37
|
-
assetsDir: "assets",
|
|
38
|
-
listeningListener: (r) => {
|
|
39
|
-
console.log(`\u{1F680} Server started on port ${r.port}`);
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
async function M(r = {}) {
|
|
43
|
-
let e = {
|
|
44
|
-
...h,
|
|
45
|
-
...r,
|
|
46
|
-
defaultLogger: r.defaultLogger ?? !0
|
|
47
|
-
}, o = process.env.NODE_ENV === "test" ? "development" : process.env.NODE_ENV, n = o === "production", t = new y(e.honoOptions), d = `./${e.buildDirectory}/server`, s = `./${e.buildDirectory}/client`;
|
|
48
|
-
return t.use(
|
|
49
|
-
`/${e.assetsDir}/*`,
|
|
50
|
-
i(60 * 60 * 24 * 365),
|
|
51
|
-
// 1 year
|
|
52
|
-
v({ root: s })
|
|
53
|
-
), t.use("*", i(60 * 60), v({ root: n ? s : "./public" })), e.defaultLogger && t.use("*", E()), e.configure && await e.configure(t), t.use(async (u, m) => {
|
|
54
|
-
let p = n ? await import(
|
|
55
|
-
/* @vite-ignore */
|
|
56
|
-
O.pathToFileURL(
|
|
57
|
-
c.resolve(c.join(process.cwd(), `${d}/${e.serverBuildFile}`))
|
|
58
|
-
).toString()
|
|
59
|
-
) : await a();
|
|
60
|
-
return x({
|
|
61
|
-
build: p,
|
|
62
|
-
mode: o,
|
|
63
|
-
getLoadContext(l) {
|
|
64
|
-
return e.getLoadContext ? e.getLoadContext(l, { build: p }) : {};
|
|
65
|
-
}
|
|
66
|
-
})(u, m);
|
|
67
|
-
}), n && g(
|
|
68
|
-
{
|
|
69
|
-
...t,
|
|
70
|
-
...e.customNodeServer,
|
|
71
|
-
port: e.port
|
|
72
|
-
},
|
|
73
|
-
e.listeningListener
|
|
74
|
-
), t;
|
|
75
|
-
}
|
|
76
|
-
export {
|
|
77
|
-
M as createHonoServer
|
|
78
|
-
};
|