react-router-hono-server 0.0.4 → 0.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 +8 -2
- package/dist/node.d.mts +12 -4
- package/dist/node.mjs +30 -30
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ That's all!
|
|
|
126
126
|
### Options
|
|
127
127
|
|
|
128
128
|
```ts
|
|
129
|
-
export type HonoServerOptions = {
|
|
129
|
+
export type HonoServerOptions<E extends Env = BlankEnv> = {
|
|
130
130
|
/**
|
|
131
131
|
* Enable the default logger
|
|
132
132
|
*
|
|
@@ -168,7 +168,7 @@ export type HonoServerOptions = {
|
|
|
168
168
|
*
|
|
169
169
|
* It is applied after the default middleware and before the remix middleware
|
|
170
170
|
*/
|
|
171
|
-
configure?: (server: Hono) => Promise<void> | void;
|
|
171
|
+
configure?: <E extends Env = BlankEnv>(server: Hono<E>) => Promise<void> | void;
|
|
172
172
|
/**
|
|
173
173
|
* Augment the Remix AppLoadContext
|
|
174
174
|
*
|
|
@@ -194,6 +194,12 @@ export type HonoServerOptions = {
|
|
|
194
194
|
* Defaults log the port
|
|
195
195
|
*/
|
|
196
196
|
listeningListener?: (info: { port: number }) => void;
|
|
197
|
+
/**
|
|
198
|
+
* Hono constructor options
|
|
199
|
+
*
|
|
200
|
+
* {@link HonoOptions}
|
|
201
|
+
*/
|
|
202
|
+
honoOptions?: HonoOptions<E>;
|
|
197
203
|
};
|
|
198
204
|
```
|
|
199
205
|
|
package/dist/node.d.mts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import * as hono_types from 'hono/types';
|
|
2
|
+
import { BlankEnv } from 'hono/types';
|
|
2
3
|
import { AppLoadContext } from '@remix-run/node';
|
|
3
|
-
import { Hono, Context } from 'hono';
|
|
4
|
+
import { Env, Hono, Context } from 'hono';
|
|
5
|
+
import { HonoOptions } from 'hono/hono-base';
|
|
4
6
|
import { RemixMiddlewareOptions } from 'remix-hono/handler';
|
|
5
7
|
|
|
6
|
-
type HonoServerOptions = {
|
|
8
|
+
type HonoServerOptions<E extends Env = BlankEnv> = {
|
|
7
9
|
/**
|
|
8
10
|
* Enable the default logger
|
|
9
11
|
*
|
|
@@ -45,7 +47,7 @@ type HonoServerOptions = {
|
|
|
45
47
|
*
|
|
46
48
|
* It is applied after the default middleware and before the remix middleware
|
|
47
49
|
*/
|
|
48
|
-
configure?: (server: Hono) => Promise<void> | void;
|
|
50
|
+
configure?: <E extends Env = BlankEnv>(server: Hono<E>) => Promise<void> | void;
|
|
49
51
|
/**
|
|
50
52
|
* Augment the Remix AppLoadContext
|
|
51
53
|
*
|
|
@@ -70,12 +72,18 @@ type HonoServerOptions = {
|
|
|
70
72
|
listeningListener?: (info: {
|
|
71
73
|
port: number;
|
|
72
74
|
}) => void;
|
|
75
|
+
/**
|
|
76
|
+
* Hono constructor options
|
|
77
|
+
*
|
|
78
|
+
* {@link HonoOptions}
|
|
79
|
+
*/
|
|
80
|
+
honoOptions?: HonoOptions<E>;
|
|
73
81
|
};
|
|
74
82
|
/**
|
|
75
83
|
* Create a Hono server
|
|
76
84
|
*
|
|
77
85
|
* @param config {@link HonoServerOptions} - The configuration options for the server
|
|
78
86
|
*/
|
|
79
|
-
declare function createHonoServer(options?: HonoServerOptions): Promise<Hono<
|
|
87
|
+
declare function createHonoServer<E extends Env = BlankEnv>(options?: HonoServerOptions<E>): Promise<Hono<E, hono_types.BlankSchema, "/">>;
|
|
80
88
|
|
|
81
89
|
export { type HonoServerOptions, createHonoServer };
|
package/dist/node.mjs
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
1
|
// src/node.ts
|
|
2
|
-
import
|
|
2
|
+
import a from "node:path";
|
|
3
3
|
import f from "node:url";
|
|
4
4
|
import { serve as g } from "@hono/node-server";
|
|
5
|
-
import { serveStatic as
|
|
6
|
-
import { Hono as
|
|
7
|
-
import { logger as
|
|
5
|
+
import { serveStatic as d } from "@hono/node-server/serve-static";
|
|
6
|
+
import { Hono as E } from "hono";
|
|
7
|
+
import { logger as x } from "hono/logger";
|
|
8
8
|
import { remix as b } from "remix-hono/handler";
|
|
9
9
|
|
|
10
10
|
// src/dev-build.ts
|
|
11
|
-
var
|
|
12
|
-
(
|
|
11
|
+
var c = process.env.NODE_ENV === "production" ? void 0 : await import("vite").then(
|
|
12
|
+
(o) => o.createServer({
|
|
13
13
|
server: { middlewareMode: !0 },
|
|
14
14
|
appType: "custom"
|
|
15
15
|
})
|
|
16
16
|
);
|
|
17
17
|
async function p() {
|
|
18
|
-
return
|
|
18
|
+
return c?.ssrLoadModule("virtual:remix/server-build");
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
// src/middleware.ts
|
|
22
22
|
import { createMiddleware as v } from "hono/factory";
|
|
23
|
-
function
|
|
23
|
+
function i(o) {
|
|
24
24
|
return v(async (e, t) => {
|
|
25
25
|
if (!e.req.path.match(/\.[a-zA-Z0-9]+$/) || e.req.path.endsWith(".data"))
|
|
26
26
|
return t();
|
|
27
|
-
await t(), e.res.ok && e.res.headers.set("cache-control", `public, max-age=${
|
|
27
|
+
await t(), e.res.ok && e.res.headers.set("cache-control", `public, max-age=${o}`);
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// src/node.ts
|
|
32
|
-
var
|
|
32
|
+
var L = {
|
|
33
33
|
defaultLogger: !0,
|
|
34
34
|
port: Number(process.env.PORT) || 3e3,
|
|
35
35
|
buildDirectory: "build/server",
|
|
36
36
|
serverBuildFile: "index.js",
|
|
37
37
|
assetsDir: "assets",
|
|
38
|
-
listeningListener: (
|
|
39
|
-
console.log(`\u{1F680} Server started on port ${
|
|
38
|
+
listeningListener: (o) => {
|
|
39
|
+
console.log(`\u{1F680} Server started on port ${o.port}`);
|
|
40
40
|
}
|
|
41
41
|
};
|
|
42
|
-
async function
|
|
42
|
+
async function M(o = {}) {
|
|
43
43
|
let e = {
|
|
44
|
-
...
|
|
45
|
-
...
|
|
46
|
-
defaultLogger:
|
|
47
|
-
}, t = process.env.NODE_ENV === "test" ? "development" : process.env.NODE_ENV,
|
|
48
|
-
return
|
|
44
|
+
...L,
|
|
45
|
+
...o,
|
|
46
|
+
defaultLogger: o.defaultLogger ?? !0
|
|
47
|
+
}, t = process.env.NODE_ENV === "test" ? "development" : process.env.NODE_ENV, n = t === "production", r = new E(e.honoOptions);
|
|
48
|
+
return r.use(
|
|
49
49
|
`/${e.assetsDir}/*`,
|
|
50
|
-
|
|
50
|
+
i(60 * 60 * 24 * 365),
|
|
51
51
|
// 1 year
|
|
52
|
-
|
|
53
|
-
),
|
|
54
|
-
let s =
|
|
52
|
+
d({ root: "./build/client" })
|
|
53
|
+
), r.use("*", i(60 * 60), d({ root: n ? "./build/client" : "./public" })), e.defaultLogger && r.use("*", x()), e.configure && await e.configure(r), r.use(async (u, l) => {
|
|
54
|
+
let s = n ? await import(
|
|
55
55
|
/* @vite-ignore */
|
|
56
56
|
f.pathToFileURL(
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
a.resolve(
|
|
58
|
+
a.join(process.cwd(), `./${e.buildDirectory}/${e.serverBuildFile}`)
|
|
59
59
|
)
|
|
60
60
|
).toString()
|
|
61
61
|
) : await p();
|
|
62
62
|
return b({
|
|
63
63
|
build: s,
|
|
64
64
|
mode: t,
|
|
65
|
-
getLoadContext(
|
|
66
|
-
return e.getLoadContext ? e.getLoadContext(
|
|
65
|
+
getLoadContext(m) {
|
|
66
|
+
return e.getLoadContext ? e.getLoadContext(m, { build: s }) : {};
|
|
67
67
|
}
|
|
68
68
|
})(u, l);
|
|
69
|
-
}),
|
|
69
|
+
}), n && g(
|
|
70
70
|
{
|
|
71
|
-
...
|
|
71
|
+
...r,
|
|
72
72
|
port: e.port
|
|
73
73
|
},
|
|
74
74
|
e.listeningListener
|
|
75
|
-
),
|
|
75
|
+
), r;
|
|
76
76
|
}
|
|
77
77
|
export {
|
|
78
|
-
|
|
78
|
+
M as createHonoServer
|
|
79
79
|
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "This package includes helper function to create an Hono app in your entry.server.tsx file. It allows you to customize your server.",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./node": {
|
|
7
7
|
"import": {
|
|
8
8
|
"import": "./dist/node.mjs",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"types": "./dist/node.d.mts",
|
|
10
|
+
"default": "./dist/node.mjs"
|
|
11
11
|
}
|
|
12
12
|
},
|
|
13
13
|
"./dev": {
|
|
14
14
|
"import": {
|
|
15
15
|
"import": "./dist/dev.mjs",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
16
|
+
"types": "./dist/dev.d.mts",
|
|
17
|
+
"default": "./dist/dev.mjs"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"./middlewares": {
|
|
21
21
|
"import": {
|
|
22
22
|
"import": "./dist/middlewares.mjs",
|
|
23
|
-
"
|
|
24
|
-
"
|
|
23
|
+
"types": "./dist/middlewares.d.mts",
|
|
24
|
+
"default": "./dist/middlewares.mjs"
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
},
|