@voyant-travel/hono 0.121.0 → 0.121.1
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/dist/lazy-routes.d.ts +1 -1
- package/dist/lazy-routes.d.ts.map +1 -1
- package/dist/lazy-routes.js +21 -2
- package/package.json +1 -1
package/dist/lazy-routes.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export interface LazyHonoRoutes {
|
|
|
49
49
|
* relative-route loaders, or `"/"` for loaders that already return absolute
|
|
50
50
|
* routes.
|
|
51
51
|
*/
|
|
52
|
-
export declare function createLazyRouteHandler(mountPrefix: string, load: LazyRoutesLoader): (c: Context) => Promise<Response>;
|
|
52
|
+
export declare function createLazyRouteHandler(mountPrefix: string, load: LazyRoutesLoader): (c: Context, next?: () => Promise<void>) => Promise<Response>;
|
|
53
53
|
/**
|
|
54
54
|
* Register a single lazy surface on `app` at `prefix` (loader returns RELATIVE
|
|
55
55
|
* routes). Matches both the prefix root (`POST /v1/admin/foo`) and any sub-path
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lazy-routes.d.ts","sourceRoot":"","sources":["../src/lazy-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAA;AAMrD,KAAK,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;AAE5B,oEAAoE;AACpE,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;AAErD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,IAAI,EAAE,gBAAgB,CAAA;CACvB;
|
|
1
|
+
{"version":3,"file":"lazy-routes.d.ts","sourceRoot":"","sources":["../src/lazy-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,IAAI,QAAQ,EAAE,MAAM,MAAM,CAAA;AAMrD,KAAK,OAAO,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAA;AAE5B,oEAAoE;AACpE,MAAM,MAAM,gBAAgB,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,CAAA;AAErD;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAA;IACxB,IAAI,EAAE,gBAAgB,CAAA;CACvB;AAgBD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,IA6ClE,GAAG,OAAO,EAAE,OAAO,MAAM,OAAO,CAAC,IAAI,CAAC,KAAG,OAAO,CAAC,QAAQ,CAAC,CAezE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAI5F;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,OAAO,EACZ,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,IAAI,EAAE,gBAAgB,GACrB,IAAI,CAKN"}
|
package/dist/lazy-routes.js
CHANGED
|
@@ -2,6 +2,16 @@ import { Hono } from "hono";
|
|
|
2
2
|
import { tryGetExecutionCtx } from "./lib/execution-ctx.js";
|
|
3
3
|
/** Private carrier key for snapshotting `c.var` across the forward. */
|
|
4
4
|
const LAZY_CONTEXT_CARRIER = Symbol.for("voyant.hono.lazyContextCarrier");
|
|
5
|
+
const LAZY_ROUTE_MISS_HEADER = "x-voyant-lazy-route-miss";
|
|
6
|
+
function withoutLazyRouteMissHeader(response) {
|
|
7
|
+
const headers = new Headers(response.headers);
|
|
8
|
+
headers.delete(LAZY_ROUTE_MISS_HEADER);
|
|
9
|
+
return new Response(response.body, {
|
|
10
|
+
status: response.status,
|
|
11
|
+
statusText: response.statusText,
|
|
12
|
+
headers,
|
|
13
|
+
});
|
|
14
|
+
}
|
|
5
15
|
/**
|
|
6
16
|
* Build a cached, context-preserving request handler. `mountPrefix` is where the
|
|
7
17
|
* loaded routes are re-mounted in the wrapper sub-app so the forwarded absolute
|
|
@@ -27,6 +37,7 @@ export function createLazyRouteHandler(mountPrefix, load) {
|
|
|
27
37
|
wrapped.onError((err) => {
|
|
28
38
|
throw err;
|
|
29
39
|
});
|
|
40
|
+
wrapped.notFound(() => new Response(null, { status: 404, headers: { [LAZY_ROUTE_MISS_HEADER]: "1" } }));
|
|
30
41
|
wrapped.use("*", async (cc, next) => {
|
|
31
42
|
const carried = cc.env?.[LAZY_CONTEXT_CARRIER];
|
|
32
43
|
if (carried) {
|
|
@@ -47,12 +58,20 @@ export function createLazyRouteHandler(mountPrefix, load) {
|
|
|
47
58
|
}
|
|
48
59
|
return cached;
|
|
49
60
|
}
|
|
50
|
-
return async (c) => {
|
|
61
|
+
return async (c, next) => {
|
|
51
62
|
const app = await getApp();
|
|
52
63
|
const snapshot = { ...c.var };
|
|
53
64
|
const env = { ...c.env, [LAZY_CONTEXT_CARRIER]: snapshot };
|
|
54
65
|
// biome-ignore lint/suspicious/noExplicitAny: forward the host execution context when present -- owner: hono.
|
|
55
|
-
|
|
66
|
+
const response = await app.fetch(c.req.raw, env, tryGetExecutionCtx(c));
|
|
67
|
+
const routeMiss = response.headers.get(LAZY_ROUTE_MISS_HEADER) === "1";
|
|
68
|
+
if (routeMiss && next) {
|
|
69
|
+
// Match eager `app.route(...)` composition: overlapping lazy mounts under
|
|
70
|
+
// the same prefix must let later modules/extensions try the request.
|
|
71
|
+
await next();
|
|
72
|
+
return c.res;
|
|
73
|
+
}
|
|
74
|
+
return routeMiss ? withoutLazyRouteMissHeader(response) : response;
|
|
56
75
|
};
|
|
57
76
|
}
|
|
58
77
|
/**
|