@hono/node-server 1.19.10 → 2.0.0-rc.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/README.md +1 -7
- package/dist/conninfo.d.mts +4 -3
- package/dist/conninfo.d.ts +4 -3
- package/dist/conninfo.js +20 -40
- package/dist/conninfo.mjs +19 -16
- package/dist/constants-B7DBcQew.js +11 -0
- package/dist/constants-DEKKqoym.mjs +5 -0
- package/dist/index.d.mts +62 -8
- package/dist/index.d.ts +62 -8
- package/dist/index.js +28 -613
- package/dist/index.mjs +24 -573
- package/dist/listener-Brd4yZ5d.js +726 -0
- package/dist/listener-RIBxK9_x.mjs +715 -0
- package/dist/serve-static.d.mts +14 -13
- package/dist/serve-static.d.ts +14 -13
- package/dist/serve-static.js +128 -170
- package/dist/serve-static.mjs +127 -145
- package/dist/utils/response.d.mts +3 -2
- package/dist/utils/response.d.ts +3 -2
- package/dist/utils/response.js +6 -35
- package/dist/utils/response.mjs +6 -9
- package/dist/vercel.d.mts +6 -5
- package/dist/vercel.d.ts +6 -5
- package/dist/vercel.js +7 -585
- package/dist/vercel.mjs +6 -548
- package/package.json +11 -13
- package/dist/globals.d.mts +0 -2
- package/dist/globals.d.ts +0 -2
- package/dist/globals.js +0 -29
- package/dist/globals.mjs +0 -5
- package/dist/listener.d.mts +0 -13
- package/dist/listener.d.ts +0 -13
- package/dist/listener.js +0 -581
- package/dist/listener.mjs +0 -546
- package/dist/request.d.mts +0 -25
- package/dist/request.d.ts +0 -25
- package/dist/request.js +0 -227
- package/dist/request.mjs +0 -195
- package/dist/response.d.mts +0 -26
- package/dist/response.d.ts +0 -26
- package/dist/response.js +0 -99
- package/dist/response.mjs +0 -72
- package/dist/server.d.mts +0 -10
- package/dist/server.d.ts +0 -10
- package/dist/server.js +0 -607
- package/dist/server.mjs +0 -571
- package/dist/types.d.mts +0 -44
- package/dist/types.d.ts +0 -44
- package/dist/types.js +0 -18
- package/dist/types.mjs +0 -0
- package/dist/utils/response/constants.d.mts +0 -3
- package/dist/utils/response/constants.d.ts +0 -3
- package/dist/utils/response/constants.js +0 -30
- package/dist/utils/response/constants.mjs +0 -5
- package/dist/utils.d.mts +0 -9
- package/dist/utils.d.ts +0 -9
- package/dist/utils.js +0 -99
- package/dist/utils.mjs +0 -71
package/dist/serve-static.mjs
CHANGED
|
@@ -1,152 +1,134 @@
|
|
|
1
|
-
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
2
|
import { getMimeType } from "hono/utils/mime";
|
|
3
|
-
import { createReadStream,
|
|
4
|
-
import { join } from "path";
|
|
5
|
-
import { versions } from "process";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
import { createReadStream, existsSync, statSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { versions } from "node:process";
|
|
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"
|
|
12
13
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
|
|
15
|
+
const pr54206Applied = () => {
|
|
16
|
+
const [major, minor] = versions.node.split(".").map((component) => parseInt(component));
|
|
17
|
+
return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return body;
|
|
19
|
+
const useReadableToWeb = pr54206Applied();
|
|
20
|
+
const createStreamBody = (stream) => {
|
|
21
|
+
if (useReadableToWeb) return Readable.toWeb(stream);
|
|
22
|
+
return new ReadableStream({
|
|
23
|
+
start(controller) {
|
|
24
|
+
stream.on("data", (chunk) => {
|
|
25
|
+
controller.enqueue(chunk);
|
|
26
|
+
});
|
|
27
|
+
stream.on("error", (err) => {
|
|
28
|
+
controller.error(err);
|
|
29
|
+
});
|
|
30
|
+
stream.on("end", () => {
|
|
31
|
+
controller.close();
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
cancel() {
|
|
35
|
+
stream.destroy();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
40
38
|
};
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return stats;
|
|
39
|
+
const getStats = (path) => {
|
|
40
|
+
let stats;
|
|
41
|
+
try {
|
|
42
|
+
stats = statSync(path);
|
|
43
|
+
} catch {}
|
|
44
|
+
return stats;
|
|
48
45
|
};
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
46
|
+
const tryDecode = (str, decoder) => {
|
|
47
|
+
try {
|
|
48
|
+
return decoder(str);
|
|
49
|
+
} catch {
|
|
50
|
+
return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
|
|
51
|
+
try {
|
|
52
|
+
return decoder(match);
|
|
53
|
+
} catch {
|
|
54
|
+
return match;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
61
58
|
};
|
|
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
|
-
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
135
|
-
const start = parseInt(parts[0], 10) || 0;
|
|
136
|
-
let end = parseInt(parts[1], 10) || size - 1;
|
|
137
|
-
if (size < end - start + 1) {
|
|
138
|
-
end = size - 1;
|
|
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
|
|
59
|
+
const tryDecodeURI = (str) => tryDecode(str, decodeURI);
|
|
60
|
+
const serveStatic = (options = { root: "" }) => {
|
|
61
|
+
const root = options.root || "";
|
|
62
|
+
const optionPath = options.path;
|
|
63
|
+
if (root !== "" && !existsSync(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
|
|
64
|
+
return async (c, next) => {
|
|
65
|
+
if (c.finalized) return next();
|
|
66
|
+
let filename;
|
|
67
|
+
if (optionPath) filename = optionPath;
|
|
68
|
+
else try {
|
|
69
|
+
filename = tryDecodeURI(c.req.path);
|
|
70
|
+
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) throw new Error();
|
|
71
|
+
} catch {
|
|
72
|
+
await options.onNotFound?.(c.req.path, c);
|
|
73
|
+
return next();
|
|
74
|
+
}
|
|
75
|
+
let path = join(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
|
|
76
|
+
let stats = getStats(path);
|
|
77
|
+
if (stats && stats.isDirectory()) {
|
|
78
|
+
const indexFile = options.index ?? "index.html";
|
|
79
|
+
path = join(path, indexFile);
|
|
80
|
+
stats = getStats(path);
|
|
81
|
+
}
|
|
82
|
+
if (!stats) {
|
|
83
|
+
await options.onNotFound?.(path, c);
|
|
84
|
+
return next();
|
|
85
|
+
}
|
|
86
|
+
const mimeType = getMimeType(path);
|
|
87
|
+
c.header("Content-Type", mimeType || "application/octet-stream");
|
|
88
|
+
if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
|
|
89
|
+
const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
|
|
90
|
+
for (const encoding of ENCODINGS_ORDERED_KEYS) {
|
|
91
|
+
if (!acceptEncodingSet.has(encoding)) continue;
|
|
92
|
+
const precompressedStats = getStats(path + ENCODINGS[encoding]);
|
|
93
|
+
if (precompressedStats) {
|
|
94
|
+
c.header("Content-Encoding", encoding);
|
|
95
|
+
c.header("Vary", "Accept-Encoding", { append: true });
|
|
96
|
+
stats = precompressedStats;
|
|
97
|
+
path = path + ENCODINGS[encoding];
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
let result;
|
|
103
|
+
const size = stats.size;
|
|
104
|
+
const range = c.req.header("range") || "";
|
|
105
|
+
if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
|
|
106
|
+
c.header("Content-Length", size.toString());
|
|
107
|
+
c.status(200);
|
|
108
|
+
result = c.body(null);
|
|
109
|
+
} else if (!range) {
|
|
110
|
+
c.header("Content-Length", size.toString());
|
|
111
|
+
result = c.body(createStreamBody(createReadStream(path)), 200);
|
|
112
|
+
} else {
|
|
113
|
+
c.header("Accept-Ranges", "bytes");
|
|
114
|
+
c.header("Date", stats.birthtime.toUTCString());
|
|
115
|
+
const parts = range.replace(/bytes=/, "").split("-", 2);
|
|
116
|
+
const start = parseInt(parts[0], 10) || 0;
|
|
117
|
+
let end = parseInt(parts[1], 10) || size - 1;
|
|
118
|
+
if (size < end - start + 1) end = size - 1;
|
|
119
|
+
const chunksize = end - start + 1;
|
|
120
|
+
const stream = createReadStream(path, {
|
|
121
|
+
start,
|
|
122
|
+
end
|
|
123
|
+
});
|
|
124
|
+
c.header("Content-Length", chunksize.toString());
|
|
125
|
+
c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
|
|
126
|
+
result = c.body(createStreamBody(stream), 206);
|
|
127
|
+
}
|
|
128
|
+
await options.onFound?.(path, c);
|
|
129
|
+
return result;
|
|
130
|
+
};
|
|
152
131
|
};
|
|
132
|
+
|
|
133
|
+
//#endregion
|
|
134
|
+
export { serveStatic };
|
package/dist/utils/response.d.ts
CHANGED
package/dist/utils/response.js
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_constants = require('../constants-B7DBcQew.js');
|
|
19
3
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
__export(response_exports, {
|
|
23
|
-
RESPONSE_ALREADY_SENT: () => RESPONSE_ALREADY_SENT
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(response_exports);
|
|
4
|
+
//#region src/utils/response.ts
|
|
5
|
+
const RESPONSE_ALREADY_SENT = new Response(null, { headers: { [require_constants.X_ALREADY_SENT]: "true" } });
|
|
26
6
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
// src/utils/response.ts
|
|
31
|
-
var RESPONSE_ALREADY_SENT = new Response(null, {
|
|
32
|
-
headers: { [X_ALREADY_SENT]: "true" }
|
|
33
|
-
});
|
|
34
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
-
0 && (module.exports = {
|
|
36
|
-
RESPONSE_ALREADY_SENT
|
|
37
|
-
});
|
|
7
|
+
//#endregion
|
|
8
|
+
exports.RESPONSE_ALREADY_SENT = RESPONSE_ALREADY_SENT;
|
package/dist/utils/response.mjs
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
var X_ALREADY_SENT = "x-hono-already-sent";
|
|
1
|
+
import { t as X_ALREADY_SENT } from "../constants-DEKKqoym.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 };
|
package/dist/vercel.d.mts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as http from
|
|
3
|
-
import
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import * as http from "http";
|
|
3
|
+
import * as http2 from "http2";
|
|
4
4
|
|
|
5
|
+
//#region src/vercel.d.ts
|
|
5
6
|
declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse | http2.Http2ServerResponse) => Promise<void>;
|
|
6
|
-
|
|
7
|
-
export { handle };
|
|
7
|
+
//#endregion
|
|
8
|
+
export { handle };
|
package/dist/vercel.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import * as http from
|
|
3
|
-
import
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import * as http from "http";
|
|
3
|
+
import * as http2 from "http2";
|
|
4
4
|
|
|
5
|
+
//#region src/vercel.d.ts
|
|
5
6
|
declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse | http2.Http2ServerResponse) => Promise<void>;
|
|
6
|
-
|
|
7
|
-
export { handle };
|
|
7
|
+
//#endregion
|
|
8
|
+
export { handle };
|