@zuplo/cli 6.73.16 → 6.73.18
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/node_modules/@hono/node-server/README.md +58 -25
- package/node_modules/@hono/node-server/dist/conninfo.cjs +22 -0
- package/node_modules/@hono/node-server/dist/{conninfo.d.ts → conninfo.d.cts} +4 -3
- package/node_modules/@hono/node-server/dist/conninfo.d.mts +4 -3
- package/node_modules/@hono/node-server/dist/conninfo.mjs +19 -16
- package/node_modules/@hono/node-server/dist/constants-BLSFu_RU.mjs +5 -0
- package/node_modules/@hono/node-server/dist/constants-BXAKTxRC.cjs +11 -0
- package/node_modules/@hono/node-server/dist/index.cjs +1173 -0
- package/node_modules/@hono/node-server/dist/index.d.cts +101 -0
- package/node_modules/@hono/node-server/dist/index.d.mts +101 -8
- package/node_modules/@hono/node-server/dist/index.mjs +1143 -637
- package/node_modules/@hono/node-server/dist/serve-static.cjs +151 -0
- package/node_modules/@hono/node-server/dist/serve-static.d.cts +18 -0
- package/node_modules/@hono/node-server/dist/serve-static.d.mts +14 -13
- package/node_modules/@hono/node-server/dist/serve-static.mjs +143 -145
- package/node_modules/@hono/node-server/dist/utils/response.cjs +8 -0
- package/node_modules/@hono/node-server/dist/utils/response.d.cts +4 -0
- package/node_modules/@hono/node-server/dist/utils/response.d.mts +3 -2
- package/node_modules/@hono/node-server/dist/utils/response.mjs +6 -9
- package/node_modules/@hono/node-server/dist/utils/stream.cjs +65 -0
- package/node_modules/@hono/node-server/dist/utils/stream.d.cts +6 -0
- package/node_modules/@hono/node-server/dist/utils/stream.d.mts +6 -0
- package/node_modules/@hono/node-server/dist/utils/stream.mjs +64 -0
- package/node_modules/@hono/node-server/package.json +65 -54
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/index.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/index.js +1 -12
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/index.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.d.ts +7 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.js +9 -3
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/stdio.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/streamableHttp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/streamableHttp.js +5 -3
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/client/streamableHttp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.js +1 -12
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.d.ts +5 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.d.ts.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.js +17 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/sseKeepAlive.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.d.ts +9 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.js +10 -4
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/stdio.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.d.ts +21 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.js +239 -41
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/webStandardStreamableHttp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/zod-compat.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/zod-compat.js +25 -6
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/server/zod-compat.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.d.ts +32 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.d.ts.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.js +64 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/mediaType.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.d.ts +5 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.js +10 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/stdio.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js +2 -13
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.d.ts +7 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js +9 -3
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/stdio.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js +5 -3
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +2 -13
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.d.ts +5 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.d.ts.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js +13 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts +9 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js +10 -4
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts +21 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js +239 -41
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +25 -6
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.d.ts +32 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.d.ts.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js +57 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js.map +1 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.d.ts +5 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.d.ts.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js +9 -0
- package/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js.map +1 -1
- package/node_modules/@modelcontextprotocol/sdk/package.json +4 -3
- package/node_modules/@zuplo/core/package.json +1 -1
- package/node_modules/@zuplo/graphql/package.json +1 -1
- package/node_modules/@zuplo/openapi-tools/package.json +1 -1
- package/node_modules/@zuplo/otel/out/esm/chunk-JYT2Q52R.js +26 -0
- package/node_modules/@zuplo/otel/out/esm/chunk-JYT2Q52R.js.map +1 -0
- package/node_modules/@zuplo/otel/out/esm/index.js +1 -1
- package/node_modules/@zuplo/otel/package.json +1 -1
- package/node_modules/@zuplo/runtime/out/esm/{chunk-OAVAM6CR.js → chunk-JPPAUB3E.js} +3 -3
- package/node_modules/@zuplo/runtime/out/esm/chunk-JPPAUB3E.js.map +1 -0
- package/node_modules/@zuplo/runtime/out/esm/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/esm/mcp-gateway/index.js +1 -1
- package/node_modules/@zuplo/runtime/out/types/index.d.ts +10 -3
- package/node_modules/@zuplo/runtime/package.json +1 -1
- package/node_modules/express-rate-limit/dist/index.d.cts +10 -12
- package/node_modules/express-rate-limit/dist/index.d.mts +10 -12
- package/node_modules/express-rate-limit/dist/index.d.ts +10 -12
- package/node_modules/express-rate-limit/package.json +5 -5
- package/node_modules/express-rate-limit/readme.md +2 -2
- package/node_modules/ip-address/README.md +102 -96
- package/node_modules/ip-address/dist/common.d.ts +23 -0
- package/node_modules/ip-address/dist/common.js +27 -4
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/dist/ipv4.d.ts +8 -1
- package/node_modules/ip-address/dist/ipv4.js +21 -8
- package/node_modules/ip-address/dist/ipv4.js.map +1 -1
- package/node_modules/ip-address/dist/ipv6.d.ts +59 -1
- package/node_modules/ip-address/dist/ipv6.js +149 -41
- package/node_modules/ip-address/dist/ipv6.js.map +1 -1
- package/node_modules/ip-address/dist/v4/constants.js +5 -1
- package/node_modules/ip-address/dist/v4/constants.js.map +1 -1
- package/node_modules/ip-address/dist/v6/constants.js +3 -2
- package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
- package/node_modules/ip-address/package.json +2 -2
- package/package.json +6 -6
- package/node_modules/@hono/node-server/dist/conninfo.js +0 -42
- package/node_modules/@hono/node-server/dist/globals.d.mts +0 -2
- package/node_modules/@hono/node-server/dist/globals.d.ts +0 -2
- package/node_modules/@hono/node-server/dist/globals.js +0 -29
- package/node_modules/@hono/node-server/dist/globals.mjs +0 -5
- package/node_modules/@hono/node-server/dist/index.d.ts +0 -8
- package/node_modules/@hono/node-server/dist/index.js +0 -702
- package/node_modules/@hono/node-server/dist/listener.d.mts +0 -13
- package/node_modules/@hono/node-server/dist/listener.d.ts +0 -13
- package/node_modules/@hono/node-server/dist/listener.js +0 -670
- package/node_modules/@hono/node-server/dist/listener.mjs +0 -635
- package/node_modules/@hono/node-server/dist/request.d.mts +0 -25
- package/node_modules/@hono/node-server/dist/request.d.ts +0 -25
- package/node_modules/@hono/node-server/dist/request.js +0 -238
- package/node_modules/@hono/node-server/dist/request.mjs +0 -206
- package/node_modules/@hono/node-server/dist/response.d.mts +0 -26
- package/node_modules/@hono/node-server/dist/response.d.ts +0 -26
- package/node_modules/@hono/node-server/dist/response.js +0 -112
- package/node_modules/@hono/node-server/dist/response.mjs +0 -85
- package/node_modules/@hono/node-server/dist/serve-static.d.ts +0 -17
- package/node_modules/@hono/node-server/dist/serve-static.js +0 -177
- package/node_modules/@hono/node-server/dist/server.d.mts +0 -10
- package/node_modules/@hono/node-server/dist/server.d.ts +0 -10
- package/node_modules/@hono/node-server/dist/server.js +0 -696
- package/node_modules/@hono/node-server/dist/server.mjs +0 -660
- package/node_modules/@hono/node-server/dist/types.d.mts +0 -44
- package/node_modules/@hono/node-server/dist/types.d.ts +0 -44
- package/node_modules/@hono/node-server/dist/types.js +0 -18
- package/node_modules/@hono/node-server/dist/types.mjs +0 -0
- package/node_modules/@hono/node-server/dist/utils/response/constants.d.mts +0 -3
- package/node_modules/@hono/node-server/dist/utils/response/constants.d.ts +0 -3
- package/node_modules/@hono/node-server/dist/utils/response/constants.js +0 -30
- package/node_modules/@hono/node-server/dist/utils/response/constants.mjs +0 -5
- package/node_modules/@hono/node-server/dist/utils/response.d.ts +0 -3
- package/node_modules/@hono/node-server/dist/utils/response.js +0 -37
- package/node_modules/@hono/node-server/dist/utils.d.mts +0 -9
- package/node_modules/@hono/node-server/dist/utils.d.ts +0 -9
- package/node_modules/@hono/node-server/dist/utils.js +0 -99
- package/node_modules/@hono/node-server/dist/utils.mjs +0 -71
- package/node_modules/@hono/node-server/dist/vercel.d.mts +0 -7
- package/node_modules/@hono/node-server/dist/vercel.d.ts +0 -7
- package/node_modules/@hono/node-server/dist/vercel.js +0 -677
- package/node_modules/@hono/node-server/dist/vercel.mjs +0 -640
- package/node_modules/@zuplo/otel/out/esm/chunk-JWNK52ES.js +0 -26
- package/node_modules/@zuplo/otel/out/esm/chunk-JWNK52ES.js.map +0 -1
- package/node_modules/@zuplo/runtime/out/esm/chunk-OAVAM6CR.js.map +0 -1
- /package/node_modules/@zuplo/runtime/out/esm/{chunk-OAVAM6CR.js.LEGAL.txt → chunk-JPPAUB3E.js.LEGAL.txt} +0 -0
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_utils_stream = require('./utils/stream.cjs');
|
|
3
|
+
let hono_utils_mime = require("hono/utils/mime");
|
|
4
|
+
let node_fs = require("node:fs");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
|
|
7
|
+
//#region src/serve-static.ts
|
|
8
|
+
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
9
|
+
const ENCODINGS = {
|
|
10
|
+
br: ".br",
|
|
11
|
+
zstd: ".zst",
|
|
12
|
+
gzip: ".gz"
|
|
13
|
+
};
|
|
14
|
+
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
15
|
+
const getStats = (path) => {
|
|
16
|
+
let stats;
|
|
17
|
+
try {
|
|
18
|
+
stats = (0, node_fs.statSync)(path);
|
|
19
|
+
} catch {}
|
|
20
|
+
return stats;
|
|
21
|
+
};
|
|
22
|
+
const BYTE_RANGE_PATTERN = /^(?:bytes=)?(?!-$)(\d*)-(\d*)$/;
|
|
23
|
+
const parseByteRange = (range) => {
|
|
24
|
+
const match = range.match(BYTE_RANGE_PATTERN);
|
|
25
|
+
if (!match) return;
|
|
26
|
+
const [, start, end] = match;
|
|
27
|
+
if (start === "") return {
|
|
28
|
+
type: "suffix",
|
|
29
|
+
length: Number(end)
|
|
30
|
+
};
|
|
31
|
+
if (end === "") return {
|
|
32
|
+
type: "open-ended",
|
|
33
|
+
start: Number(start)
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
type: "bounded",
|
|
37
|
+
start: Number(start),
|
|
38
|
+
end: Number(end)
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const resolveByteRange = (spec, size) => {
|
|
42
|
+
if (size === 0) return;
|
|
43
|
+
if (spec.type === "suffix") {
|
|
44
|
+
if (spec.length === 0) return;
|
|
45
|
+
return {
|
|
46
|
+
start: Math.max(size - spec.length, 0),
|
|
47
|
+
end: size - 1
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const end = spec.type === "bounded" ? Math.min(spec.end, size - 1) : size - 1;
|
|
51
|
+
if (spec.start >= size || spec.start > end) return;
|
|
52
|
+
return {
|
|
53
|
+
start: spec.start,
|
|
54
|
+
end
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
const tryDecode = (str, decoder) => {
|
|
58
|
+
try {
|
|
59
|
+
return decoder(str);
|
|
60
|
+
} catch {
|
|
61
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
62
|
+
try {
|
|
63
|
+
return decoder(match);
|
|
64
|
+
} catch {
|
|
65
|
+
return match;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
71
|
+
const serveStatic = (options = { root: "" }) => {
|
|
72
|
+
const root = options.root || "";
|
|
73
|
+
const optionPath = options.path;
|
|
74
|
+
if (root !== "" && !(0, node_fs.existsSync)(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
|
|
75
|
+
return async (c, next) => {
|
|
76
|
+
if (c.finalized) return next();
|
|
77
|
+
let filename;
|
|
78
|
+
if (optionPath) filename = optionPath;
|
|
79
|
+
else try {
|
|
80
|
+
filename = tryDecodeURI(c.req.path);
|
|
81
|
+
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
|
|
82
|
+
} catch {
|
|
83
|
+
await options.onNotFound?.(c.req.path, c);
|
|
84
|
+
return next();
|
|
85
|
+
}
|
|
86
|
+
let path = (0, node_path.join)(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
|
87
|
+
let stats = getStats(path);
|
|
88
|
+
if (stats && stats.isDirectory()) {
|
|
89
|
+
const indexFile = options.index ?? "index.html";
|
|
90
|
+
path = (0, node_path.join)(path, indexFile);
|
|
91
|
+
stats = getStats(path);
|
|
92
|
+
}
|
|
93
|
+
if (!stats) {
|
|
94
|
+
await options.onNotFound?.(path, c);
|
|
95
|
+
return next();
|
|
96
|
+
}
|
|
97
|
+
const mimeType = (0, hono_utils_mime.getMimeType)(path);
|
|
98
|
+
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
99
|
+
if (options.precompressed && (!mimeType || mimeType === "application/octet-stream" || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
100
|
+
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
|
101
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
102
|
+
if (!acceptEncodingSet.has(encoding)) continue;
|
|
103
|
+
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
|
104
|
+
if (precompressedStats) {
|
|
105
|
+
c.header("Content-Encoding", encoding);
|
|
106
|
+
c.header("Vary", "Accept-Encoding", { append: true });
|
|
107
|
+
stats = precompressedStats;
|
|
108
|
+
path = path + ENCODINGS[encoding];
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
let result;
|
|
114
|
+
const size = stats.size;
|
|
115
|
+
const range = c.req.header("range") || "";
|
|
116
|
+
c.header("Last-Modified", stats.mtime.toUTCString());
|
|
117
|
+
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
|
|
118
|
+
c.header("Content-Length", size.toString());
|
|
119
|
+
c.status(200);
|
|
120
|
+
result = c.body(null);
|
|
121
|
+
} else if (!range) {
|
|
122
|
+
c.header("Content-Length", size.toString());
|
|
123
|
+
result = c.body(require_utils_stream.createStreamBody((0, node_fs.createReadStream)(path)), 200);
|
|
124
|
+
} else {
|
|
125
|
+
c.header("Accept-Ranges", "bytes");
|
|
126
|
+
const resolvedRange = resolveByteRange(parseByteRange(range) ?? {
|
|
127
|
+
type: "open-ended",
|
|
128
|
+
start: 0
|
|
129
|
+
}, size);
|
|
130
|
+
if (!resolvedRange) {
|
|
131
|
+
c.header("Content-Range", `bytes */${size}`);
|
|
132
|
+
result = c.body(null, 416);
|
|
133
|
+
} else {
|
|
134
|
+
const { start, end } = resolvedRange;
|
|
135
|
+
const chunkSize = end - start + 1;
|
|
136
|
+
const stream = (0, node_fs.createReadStream)(path, {
|
|
137
|
+
start,
|
|
138
|
+
end
|
|
139
|
+
});
|
|
140
|
+
c.header("Content-Length", chunkSize.toString());
|
|
141
|
+
c.header("Content-Range", `bytes ${start}-${end}/${size}`);
|
|
142
|
+
result = c.body(require_utils_stream.createStreamBody(stream), 206);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
await options.onFound?.(path, c);
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
//#endregion
|
|
151
|
+
exports.serveStatic = serveStatic;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Context, Env, MiddlewareHandler } from "hono";
|
|
2
|
+
|
|
3
|
+
//#region src/serve-static.d.ts
|
|
4
|
+
type ServeStaticOptions<E extends Env = Env> = {
|
|
5
|
+
/**
|
|
6
|
+
* Root path. Relative path is based on current working directory from which the app was started.
|
|
7
|
+
*/
|
|
8
|
+
root?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
index?: string;
|
|
11
|
+
precompressed?: boolean;
|
|
12
|
+
rewriteRequestPath?: (path: string, c: Context<E>) => string;
|
|
13
|
+
onFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
14
|
+
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
15
|
+
};
|
|
16
|
+
declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ServeStaticOptions, serveStatic };
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Context, Env, MiddlewareHandler } from "hono";
|
|
2
2
|
|
|
3
|
+
//#region src/serve-static.d.ts
|
|
3
4
|
type ServeStaticOptions<E extends Env = Env> = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Root path. Relative path is based on current working directory from which the app was started.
|
|
7
|
+
*/
|
|
8
|
+
root?: string;
|
|
9
|
+
path?: string;
|
|
10
|
+
index?: string;
|
|
11
|
+
precompressed?: boolean;
|
|
12
|
+
rewriteRequestPath?: (path: string, c: Context<E>) => string;
|
|
13
|
+
onFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
14
|
+
onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
|
|
14
15
|
};
|
|
15
16
|
declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
|
|
16
|
-
|
|
17
|
-
export {
|
|
17
|
+
//#endregion
|
|
18
|
+
export { ServeStaticOptions, serveStatic };
|
|
@@ -1,152 +1,150 @@
|
|
|
1
|
-
|
|
1
|
+
import { createStreamBody } from "./utils/stream.mjs";
|
|
2
2
|
import { getMimeType } from "hono/utils/mime";
|
|
3
|
-
import { createReadStream,
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
|
|
6
|
+
//#region src/serve-static.ts
|
|
7
|
+
const COMPRESSIBLE_CONTENT_TYPE_REGEX = /^\s*(?:text\/[^;\s]+|application\/(?:javascript|json|xml|xml-dtd|ecmascript|dart|postscript|rtf|tar|toml|vnd\.dart|vnd\.ms-fontobject|vnd\.ms-opentype|wasm|x-httpd-php|x-javascript|x-ns-proxy-autoconfig|x-sh|x-tar|x-virtualbox-hdd|x-virtualbox-ova|x-virtualbox-ovf|x-virtualbox-vbox|x-virtualbox-vdi|x-virtualbox-vhd|x-virtualbox-vmdk|x-www-form-urlencoded)|font\/(?:otf|ttf)|image\/(?:bmp|vnd\.adobe\.photoshop|vnd\.microsoft\.icon|vnd\.ms-dds|x-icon|x-ms-bmp)|message\/rfc822|model\/gltf-binary|x-shader\/x-fragment|x-shader\/x-vertex|[^;\s]+?\+(?:json|text|xml|yaml))(?:[;\s]|$)/i;
|
|
8
|
+
const ENCODINGS = {
|
|
9
|
+
br: ".br",
|
|
10
|
+
zstd: ".zst",
|
|
11
|
+
gzip: ".gz"
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
14
|
+
const getStats = (path) => {
|
|
15
|
+
let stats;
|
|
16
|
+
try {
|
|
17
|
+
stats = statSync(path);
|
|
18
|
+
} catch {}
|
|
19
|
+
return stats;
|
|
17
20
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
stream.destroy();
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return body;
|
|
21
|
+
const BYTE_RANGE_PATTERN = /^(?:bytes=)?(?!-$)(\d*)-(\d*)$/;
|
|
22
|
+
const parseByteRange = (range) => {
|
|
23
|
+
const match = range.match(BYTE_RANGE_PATTERN);
|
|
24
|
+
if (!match) return;
|
|
25
|
+
const [, start, end] = match;
|
|
26
|
+
if (start === "") return {
|
|
27
|
+
type: "suffix",
|
|
28
|
+
length: Number(end)
|
|
29
|
+
};
|
|
30
|
+
if (end === "") return {
|
|
31
|
+
type: "open-ended",
|
|
32
|
+
start: Number(start)
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
type: "bounded",
|
|
36
|
+
start: Number(start),
|
|
37
|
+
end: Number(end)
|
|
38
|
+
};
|
|
40
39
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
40
|
+
const resolveByteRange = (spec, size) => {
|
|
41
|
+
if (size === 0) return;
|
|
42
|
+
if (spec.type === "suffix") {
|
|
43
|
+
if (spec.length === 0) return;
|
|
44
|
+
return {
|
|
45
|
+
start: Math.max(size - spec.length, 0),
|
|
46
|
+
end: size - 1
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const end = spec.type === "bounded" ? Math.min(spec.end, size - 1) : size - 1;
|
|
50
|
+
if (spec.start >= size || spec.start > end) return;
|
|
51
|
+
return {
|
|
52
|
+
start: spec.start,
|
|
53
|
+
end
|
|
54
|
+
};
|
|
48
55
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
const tryDecode = (str, decoder) => {
|
|
57
|
+
try {
|
|
58
|
+
return decoder(str);
|
|
59
|
+
} catch {
|
|
60
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
61
|
+
try {
|
|
62
|
+
return decoder(match);
|
|
63
|
+
} catch {
|
|
64
|
+
return match;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
61
68
|
};
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
const chunksize = end - start + 1;
|
|
141
|
-
const stream = createReadStream(path, { start, end });
|
|
142
|
-
c.header("Content-Length", chunksize.toString());
|
|
143
|
-
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
144
|
-
result = c.body(createStreamBody(stream), 206);
|
|
145
|
-
}
|
|
146
|
-
await options.onFound?.(path, c);
|
|
147
|
-
return result;
|
|
148
|
-
};
|
|
149
|
-
};
|
|
150
|
-
export {
|
|
151
|
-
serveStatic
|
|
69
|
+
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
70
|
+
const serveStatic = (options = { root: "" }) => {
|
|
71
|
+
const root = options.root || "";
|
|
72
|
+
const optionPath = options.path;
|
|
73
|
+
if (root !== "" && !existsSync(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
|
|
74
|
+
return async (c, next) => {
|
|
75
|
+
if (c.finalized) return next();
|
|
76
|
+
let filename;
|
|
77
|
+
if (optionPath) filename = optionPath;
|
|
78
|
+
else try {
|
|
79
|
+
filename = tryDecodeURI(c.req.path);
|
|
80
|
+
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
|
|
81
|
+
} catch {
|
|
82
|
+
await options.onNotFound?.(c.req.path, c);
|
|
83
|
+
return next();
|
|
84
|
+
}
|
|
85
|
+
let path = join(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
|
86
|
+
let stats = getStats(path);
|
|
87
|
+
if (stats && stats.isDirectory()) {
|
|
88
|
+
const indexFile = options.index ?? "index.html";
|
|
89
|
+
path = join(path, indexFile);
|
|
90
|
+
stats = getStats(path);
|
|
91
|
+
}
|
|
92
|
+
if (!stats) {
|
|
93
|
+
await options.onNotFound?.(path, c);
|
|
94
|
+
return next();
|
|
95
|
+
}
|
|
96
|
+
const mimeType = getMimeType(path);
|
|
97
|
+
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
98
|
+
if (options.precompressed && (!mimeType || mimeType === "application/octet-stream" || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
99
|
+
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
|
100
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
101
|
+
if (!acceptEncodingSet.has(encoding)) continue;
|
|
102
|
+
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
|
103
|
+
if (precompressedStats) {
|
|
104
|
+
c.header("Content-Encoding", encoding);
|
|
105
|
+
c.header("Vary", "Accept-Encoding", { append: true });
|
|
106
|
+
stats = precompressedStats;
|
|
107
|
+
path = path + ENCODINGS[encoding];
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
let result;
|
|
113
|
+
const size = stats.size;
|
|
114
|
+
const range = c.req.header("range") || "";
|
|
115
|
+
c.header("Last-Modified", stats.mtime.toUTCString());
|
|
116
|
+
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
|
|
117
|
+
c.header("Content-Length", size.toString());
|
|
118
|
+
c.status(200);
|
|
119
|
+
result = c.body(null);
|
|
120
|
+
} else if (!range) {
|
|
121
|
+
c.header("Content-Length", size.toString());
|
|
122
|
+
result = c.body(createStreamBody(createReadStream(path)), 200);
|
|
123
|
+
} else {
|
|
124
|
+
c.header("Accept-Ranges", "bytes");
|
|
125
|
+
const resolvedRange = resolveByteRange(parseByteRange(range) ?? {
|
|
126
|
+
type: "open-ended",
|
|
127
|
+
start: 0
|
|
128
|
+
}, size);
|
|
129
|
+
if (!resolvedRange) {
|
|
130
|
+
c.header("Content-Range", `bytes */${size}`);
|
|
131
|
+
result = c.body(null, 416);
|
|
132
|
+
} else {
|
|
133
|
+
const { start, end } = resolvedRange;
|
|
134
|
+
const chunkSize = end - start + 1;
|
|
135
|
+
const stream = createReadStream(path, {
|
|
136
|
+
start,
|
|
137
|
+
end
|
|
138
|
+
});
|
|
139
|
+
c.header("Content-Length", chunkSize.toString());
|
|
140
|
+
c.header("Content-Range", `bytes ${start}-${end}/${size}`);
|
|
141
|
+
result = c.body(createStreamBody(stream), 206);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
await options.onFound?.(path, c);
|
|
145
|
+
return result;
|
|
146
|
+
};
|
|
152
147
|
};
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
export { serveStatic };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_constants = require('../constants-BXAKTxRC.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/utils/response.ts
|
|
5
|
+
const RESPONSE_ALREADY_SENT = new Response(null, { headers: { [require_constants.X_ALREADY_SENT]: "true" } });
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.RESPONSE_ALREADY_SENT = RESPONSE_ALREADY_SENT;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
1
|
+
import { t as X_ALREADY_SENT } from "../constants-BLSFu_RU.mjs";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export {
|
|
9
|
-
RESPONSE_ALREADY_SENT
|
|
10
|
-
};
|
|
3
|
+
//#region src/utils/response.ts
|
|
4
|
+
const RESPONSE_ALREADY_SENT = new Response(null, { headers: { [X_ALREADY_SENT]: "true" } });
|
|
5
|
+
|
|
6
|
+
//#endregion
|
|
7
|
+
export { RESPONSE_ALREADY_SENT };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let node_stream = require("node:stream");
|
|
3
|
+
let node_process = require("node:process");
|
|
4
|
+
|
|
5
|
+
//#region src/utils/stream.ts
|
|
6
|
+
const pr54206Applied = () => {
|
|
7
|
+
const [major, minor] = node_process.versions.node.split(".").map((component) => parseInt(component));
|
|
8
|
+
return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
|
|
9
|
+
};
|
|
10
|
+
const useReadableToWeb = pr54206Applied();
|
|
11
|
+
const createStreamBody = (stream, useNativeReadableToWeb = useReadableToWeb) => {
|
|
12
|
+
if (useNativeReadableToWeb) return node_stream.Readable.toWeb(stream);
|
|
13
|
+
let controller;
|
|
14
|
+
let settled = false;
|
|
15
|
+
const cleanup = () => {
|
|
16
|
+
stream.off("data", onData);
|
|
17
|
+
stream.off("error", onError);
|
|
18
|
+
stream.off("end", onTerminate);
|
|
19
|
+
stream.off("close", onTerminate);
|
|
20
|
+
};
|
|
21
|
+
const settle = (callback) => {
|
|
22
|
+
if (settled) return;
|
|
23
|
+
settled = true;
|
|
24
|
+
cleanup();
|
|
25
|
+
callback?.();
|
|
26
|
+
};
|
|
27
|
+
const onData = (chunk) => {
|
|
28
|
+
if (settled || !controller) return;
|
|
29
|
+
controller.enqueue(chunk);
|
|
30
|
+
if ((controller.desiredSize ?? 0) <= 0) stream.pause();
|
|
31
|
+
};
|
|
32
|
+
const onError = (error) => {
|
|
33
|
+
settle(() => {
|
|
34
|
+
controller?.error(error);
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const onTerminate = () => {
|
|
38
|
+
settle(() => {
|
|
39
|
+
controller?.close();
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
return new ReadableStream({
|
|
43
|
+
start(streamController) {
|
|
44
|
+
controller = streamController;
|
|
45
|
+
stream.on("data", onData);
|
|
46
|
+
stream.on("error", onError);
|
|
47
|
+
stream.on("end", onTerminate);
|
|
48
|
+
stream.on("close", onTerminate);
|
|
49
|
+
stream.pause();
|
|
50
|
+
},
|
|
51
|
+
pull() {
|
|
52
|
+
if (!settled) stream.resume();
|
|
53
|
+
},
|
|
54
|
+
cancel() {
|
|
55
|
+
settle();
|
|
56
|
+
const ignoreError = () => {};
|
|
57
|
+
stream.on("error", ignoreError);
|
|
58
|
+
stream.once("close", () => stream.off("error", ignoreError));
|
|
59
|
+
stream.destroy();
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
//#endregion
|
|
65
|
+
exports.createStreamBody = createStreamBody;
|