hono 4.2.2 → 4.2.3
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/cjs/client/client.js +4 -1
- package/dist/cjs/client/utils.js +12 -2
- package/dist/cjs/helper/ssg/index.js +2 -2
- package/dist/cjs/helper/ssg/middleware.js +15 -2
- package/dist/cjs/helper/ssg/ssg.js +1 -1
- package/dist/client/client.js +11 -2
- package/dist/client/utils.js +10 -1
- package/dist/helper/ssg/index.js +8 -2
- package/dist/helper/ssg/middleware.js +14 -2
- package/dist/helper/ssg/ssg.js +2 -2
- package/dist/types/client/utils.d.ts +1 -0
- package/dist/types/helper/ssg/index.d.ts +1 -1
- package/dist/types/helper/ssg/middleware.d.ts +6 -0
- package/package.json +4 -1
|
@@ -134,7 +134,10 @@ const hc = (baseUrl, options) => createProxy((opts) => {
|
|
|
134
134
|
return new URL(url);
|
|
135
135
|
}
|
|
136
136
|
if (method === "ws") {
|
|
137
|
-
const targetUrl =
|
|
137
|
+
const targetUrl = (0, import_utils.replaceUrlProtocol)(
|
|
138
|
+
opts.args[0] && opts.args[0].param ? (0, import_utils.replaceUrlParam)(url, opts.args[0].param) : url,
|
|
139
|
+
"ws"
|
|
140
|
+
);
|
|
138
141
|
return new WebSocket(targetUrl);
|
|
139
142
|
}
|
|
140
143
|
const req = new ClientRequestImpl(url, method);
|
package/dist/cjs/client/utils.js
CHANGED
|
@@ -21,7 +21,8 @@ __export(utils_exports, {
|
|
|
21
21
|
deepMerge: () => deepMerge,
|
|
22
22
|
mergePath: () => mergePath,
|
|
23
23
|
removeIndexString: () => removeIndexString,
|
|
24
|
-
replaceUrlParam: () => replaceUrlParam
|
|
24
|
+
replaceUrlParam: () => replaceUrlParam,
|
|
25
|
+
replaceUrlProtocol: () => replaceUrlProtocol
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(utils_exports);
|
|
27
28
|
const mergePath = (base, path) => {
|
|
@@ -37,6 +38,14 @@ const replaceUrlParam = (urlString, params) => {
|
|
|
37
38
|
}
|
|
38
39
|
return urlString;
|
|
39
40
|
};
|
|
41
|
+
const replaceUrlProtocol = (urlString, protocol) => {
|
|
42
|
+
switch (protocol) {
|
|
43
|
+
case "ws":
|
|
44
|
+
return urlString.replace(/^http/, "ws");
|
|
45
|
+
case "http":
|
|
46
|
+
return urlString.replace(/^ws/, "http");
|
|
47
|
+
}
|
|
48
|
+
};
|
|
40
49
|
const removeIndexString = (urlSting) => {
|
|
41
50
|
return urlSting.replace(/\/index$/, "");
|
|
42
51
|
};
|
|
@@ -63,5 +72,6 @@ function deepMerge(target, source) {
|
|
|
63
72
|
deepMerge,
|
|
64
73
|
mergePath,
|
|
65
74
|
removeIndexString,
|
|
66
|
-
replaceUrlParam
|
|
75
|
+
replaceUrlParam,
|
|
76
|
+
replaceUrlProtocol
|
|
67
77
|
});
|
|
@@ -19,7 +19,7 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var ssg_exports = {};
|
|
21
21
|
__export(ssg_exports, {
|
|
22
|
-
|
|
22
|
+
X_HONO_DISABLE_SSG_HEADER_KEY: () => import_middleware.X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
23
23
|
disableSSG: () => import_middleware.disableSSG,
|
|
24
24
|
isSSGContext: () => import_middleware.isSSGContext,
|
|
25
25
|
onlySSG: () => import_middleware.onlySSG,
|
|
@@ -30,7 +30,7 @@ __reExport(ssg_exports, require("./ssg"), module.exports);
|
|
|
30
30
|
var import_middleware = require("./middleware");
|
|
31
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32
32
|
0 && (module.exports = {
|
|
33
|
-
|
|
33
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
34
34
|
disableSSG,
|
|
35
35
|
isSSGContext,
|
|
36
36
|
onlySSG,
|
|
@@ -20,6 +20,7 @@ var middleware_exports = {};
|
|
|
20
20
|
__export(middleware_exports, {
|
|
21
21
|
SSG_CONTEXT: () => SSG_CONTEXT,
|
|
22
22
|
SSG_DISABLED_RESPONSE: () => SSG_DISABLED_RESPONSE,
|
|
23
|
+
X_HONO_DISABLE_SSG_HEADER_KEY: () => X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
23
24
|
disableSSG: () => disableSSG,
|
|
24
25
|
isSSGContext: () => isSSGContext,
|
|
25
26
|
onlySSG: () => onlySSG,
|
|
@@ -27,7 +28,17 @@ __export(middleware_exports, {
|
|
|
27
28
|
});
|
|
28
29
|
module.exports = __toCommonJS(middleware_exports);
|
|
29
30
|
const SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
30
|
-
const
|
|
31
|
+
const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
32
|
+
const SSG_DISABLED_RESPONSE = (() => {
|
|
33
|
+
try {
|
|
34
|
+
return new Response("SSG is disabled", {
|
|
35
|
+
status: 404,
|
|
36
|
+
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
|
|
37
|
+
});
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
})();
|
|
31
42
|
const ssgParams = (params) => async (c, next) => {
|
|
32
43
|
;
|
|
33
44
|
c.req.raw.ssgParams = Array.isArray(params) ? params : await params(c);
|
|
@@ -36,7 +47,8 @@ const ssgParams = (params) => async (c, next) => {
|
|
|
36
47
|
const isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
|
|
37
48
|
const disableSSG = () => async function disableSSG2(c, next) {
|
|
38
49
|
if (isSSGContext(c)) {
|
|
39
|
-
|
|
50
|
+
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
|
|
51
|
+
return c.notFound();
|
|
40
52
|
}
|
|
41
53
|
await next();
|
|
42
54
|
};
|
|
@@ -50,6 +62,7 @@ const onlySSG = () => async function onlySSG2(c, next) {
|
|
|
50
62
|
0 && (module.exports = {
|
|
51
63
|
SSG_CONTEXT,
|
|
52
64
|
SSG_DISABLED_RESPONSE,
|
|
65
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
53
66
|
disableSSG,
|
|
54
67
|
isSSGContext,
|
|
55
68
|
onlySSG,
|
|
@@ -109,7 +109,7 @@ const fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook,
|
|
|
109
109
|
[import_middleware.SSG_CONTEXT]: true
|
|
110
110
|
})
|
|
111
111
|
);
|
|
112
|
-
if (response
|
|
112
|
+
if (response.headers.get(import_middleware.X_HONO_DISABLE_SSG_HEADER_KEY)) {
|
|
113
113
|
resolveReq(void 0);
|
|
114
114
|
return;
|
|
115
115
|
}
|
package/dist/client/client.js
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
// src/client/client.ts
|
|
2
2
|
import { serialize } from "../utils/cookie.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
deepMerge,
|
|
5
|
+
mergePath,
|
|
6
|
+
removeIndexString,
|
|
7
|
+
replaceUrlParam,
|
|
8
|
+
replaceUrlProtocol
|
|
9
|
+
} from "./utils.js";
|
|
4
10
|
var createProxy = (callback, path) => {
|
|
5
11
|
const proxy = new Proxy(() => {
|
|
6
12
|
}, {
|
|
@@ -112,7 +118,10 @@ var hc = (baseUrl, options) => createProxy((opts) => {
|
|
|
112
118
|
return new URL(url);
|
|
113
119
|
}
|
|
114
120
|
if (method === "ws") {
|
|
115
|
-
const targetUrl =
|
|
121
|
+
const targetUrl = replaceUrlProtocol(
|
|
122
|
+
opts.args[0] && opts.args[0].param ? replaceUrlParam(url, opts.args[0].param) : url,
|
|
123
|
+
"ws"
|
|
124
|
+
);
|
|
116
125
|
return new WebSocket(targetUrl);
|
|
117
126
|
}
|
|
118
127
|
const req = new ClientRequestImpl(url, method);
|
package/dist/client/utils.js
CHANGED
|
@@ -12,6 +12,14 @@ var replaceUrlParam = (urlString, params) => {
|
|
|
12
12
|
}
|
|
13
13
|
return urlString;
|
|
14
14
|
};
|
|
15
|
+
var replaceUrlProtocol = (urlString, protocol) => {
|
|
16
|
+
switch (protocol) {
|
|
17
|
+
case "ws":
|
|
18
|
+
return urlString.replace(/^http/, "ws");
|
|
19
|
+
case "http":
|
|
20
|
+
return urlString.replace(/^ws/, "http");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
15
23
|
var removeIndexString = (urlSting) => {
|
|
16
24
|
return urlSting.replace(/\/index$/, "");
|
|
17
25
|
};
|
|
@@ -37,5 +45,6 @@ export {
|
|
|
37
45
|
deepMerge,
|
|
38
46
|
mergePath,
|
|
39
47
|
removeIndexString,
|
|
40
|
-
replaceUrlParam
|
|
48
|
+
replaceUrlParam,
|
|
49
|
+
replaceUrlProtocol
|
|
41
50
|
};
|
package/dist/helper/ssg/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
// src/helper/ssg/index.ts
|
|
2
2
|
export * from "./ssg.js";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
5
|
+
ssgParams,
|
|
6
|
+
isSSGContext,
|
|
7
|
+
disableSSG,
|
|
8
|
+
onlySSG
|
|
9
|
+
} from "./middleware.js";
|
|
4
10
|
export {
|
|
5
|
-
|
|
11
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
6
12
|
disableSSG,
|
|
7
13
|
isSSGContext,
|
|
8
14
|
onlySSG,
|
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
// src/helper/ssg/middleware.ts
|
|
2
2
|
var SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
3
|
-
var
|
|
3
|
+
var X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
4
|
+
var SSG_DISABLED_RESPONSE = (() => {
|
|
5
|
+
try {
|
|
6
|
+
return new Response("SSG is disabled", {
|
|
7
|
+
status: 404,
|
|
8
|
+
headers: { [X_HONO_DISABLE_SSG_HEADER_KEY]: "true" }
|
|
9
|
+
});
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
})();
|
|
4
14
|
var ssgParams = (params) => async (c, next) => {
|
|
5
15
|
;
|
|
6
16
|
c.req.raw.ssgParams = Array.isArray(params) ? params : await params(c);
|
|
@@ -9,7 +19,8 @@ var ssgParams = (params) => async (c, next) => {
|
|
|
9
19
|
var isSSGContext = (c) => !!c.env?.[SSG_CONTEXT];
|
|
10
20
|
var disableSSG = () => async function disableSSG2(c, next) {
|
|
11
21
|
if (isSSGContext(c)) {
|
|
12
|
-
|
|
22
|
+
c.header(X_HONO_DISABLE_SSG_HEADER_KEY, "true");
|
|
23
|
+
return c.notFound();
|
|
13
24
|
}
|
|
14
25
|
await next();
|
|
15
26
|
};
|
|
@@ -22,6 +33,7 @@ var onlySSG = () => async function onlySSG2(c, next) {
|
|
|
22
33
|
export {
|
|
23
34
|
SSG_CONTEXT,
|
|
24
35
|
SSG_DISABLED_RESPONSE,
|
|
36
|
+
X_HONO_DISABLE_SSG_HEADER_KEY,
|
|
25
37
|
disableSSG,
|
|
26
38
|
isSSGContext,
|
|
27
39
|
onlySSG,
|
package/dist/helper/ssg/ssg.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { replaceUrlParam } from "../../client/utils.js";
|
|
3
3
|
import { createPool } from "../../utils/concurrent.js";
|
|
4
4
|
import { getExtension } from "../../utils/mime.js";
|
|
5
|
-
import {
|
|
5
|
+
import { X_HONO_DISABLE_SSG_HEADER_KEY, SSG_CONTEXT } from "./middleware.js";
|
|
6
6
|
import { joinPaths, dirname, filterStaticGenerateRoutes } from "./utils.js";
|
|
7
7
|
var DEFAULT_CONCURRENCY = 2;
|
|
8
8
|
var generateFilePath = (routePath, outDir, mimeType, extensionMap) => {
|
|
@@ -84,7 +84,7 @@ var fetchRoutesContent = function* (app, beforeRequestHook, afterResponseHook, c
|
|
|
84
84
|
[SSG_CONTEXT]: true
|
|
85
85
|
})
|
|
86
86
|
);
|
|
87
|
-
if (response
|
|
87
|
+
if (response.headers.get(X_HONO_DISABLE_SSG_HEADER_KEY)) {
|
|
88
88
|
resolveReq(void 0);
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export declare const mergePath: (base: string, path: string) => string;
|
|
2
2
|
export declare const replaceUrlParam: (urlString: string, params: Record<string, string>) => string;
|
|
3
|
+
export declare const replaceUrlProtocol: (urlString: string, protocol: 'ws' | 'http') => string;
|
|
3
4
|
export declare const removeIndexString: (urlSting: string) => string;
|
|
4
5
|
export declare function deepMerge<T>(target: T, source: Record<string, unknown>): T;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export * from './ssg';
|
|
2
|
-
export {
|
|
2
|
+
export { X_HONO_DISABLE_SSG_HEADER_KEY, ssgParams, isSSGContext, disableSSG, onlySSG, } from './middleware';
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Context } from '../../context';
|
|
2
2
|
import type { Env, MiddlewareHandler } from '../../types';
|
|
3
3
|
export declare const SSG_CONTEXT = "HONO_SSG_CONTEXT";
|
|
4
|
+
export declare const X_HONO_DISABLE_SSG_HEADER_KEY = "x-hono-disable-ssg";
|
|
5
|
+
/**
|
|
6
|
+
* @deprecated
|
|
7
|
+
* Use `X_HONO_DISABLE_SSG_HEADER_KEY` instead.
|
|
8
|
+
* This constant will be removed in the next minor version.
|
|
9
|
+
*/
|
|
4
10
|
export declare const SSG_DISABLED_RESPONSE: Response;
|
|
5
11
|
interface SSGParam {
|
|
6
12
|
[key: string]: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.3",
|
|
4
4
|
"description": "Ultrafast web framework for the Edges",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -382,6 +382,9 @@
|
|
|
382
382
|
"etag": [
|
|
383
383
|
"./dist/types/middleware/etag"
|
|
384
384
|
],
|
|
385
|
+
"trailing-slash": [
|
|
386
|
+
"./dist/types/middleware/trailing-slash"
|
|
387
|
+
],
|
|
385
388
|
"html": [
|
|
386
389
|
"./dist/types/helper/html"
|
|
387
390
|
],
|