@hono/node-server 1.19.11 → 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.
Files changed (58) hide show
  1. package/README.md +1 -7
  2. package/dist/conninfo.d.mts +4 -3
  3. package/dist/conninfo.d.ts +4 -3
  4. package/dist/conninfo.js +20 -40
  5. package/dist/conninfo.mjs +19 -16
  6. package/dist/constants-B7DBcQew.js +11 -0
  7. package/dist/constants-DEKKqoym.mjs +5 -0
  8. package/dist/index.d.mts +62 -8
  9. package/dist/index.d.ts +62 -8
  10. package/dist/index.js +28 -632
  11. package/dist/index.mjs +24 -592
  12. package/dist/listener-Brd4yZ5d.js +726 -0
  13. package/dist/listener-RIBxK9_x.mjs +715 -0
  14. package/dist/serve-static.d.mts +14 -13
  15. package/dist/serve-static.d.ts +14 -13
  16. package/dist/serve-static.js +128 -170
  17. package/dist/serve-static.mjs +127 -145
  18. package/dist/utils/response.d.mts +3 -2
  19. package/dist/utils/response.d.ts +3 -2
  20. package/dist/utils/response.js +6 -35
  21. package/dist/utils/response.mjs +6 -9
  22. package/dist/vercel.d.mts +6 -5
  23. package/dist/vercel.d.ts +6 -5
  24. package/dist/vercel.js +7 -604
  25. package/dist/vercel.mjs +6 -567
  26. package/package.json +11 -13
  27. package/dist/globals.d.mts +0 -2
  28. package/dist/globals.d.ts +0 -2
  29. package/dist/globals.js +0 -29
  30. package/dist/globals.mjs +0 -5
  31. package/dist/listener.d.mts +0 -13
  32. package/dist/listener.d.ts +0 -13
  33. package/dist/listener.js +0 -600
  34. package/dist/listener.mjs +0 -565
  35. package/dist/request.d.mts +0 -25
  36. package/dist/request.d.ts +0 -25
  37. package/dist/request.js +0 -227
  38. package/dist/request.mjs +0 -195
  39. package/dist/response.d.mts +0 -26
  40. package/dist/response.d.ts +0 -26
  41. package/dist/response.js +0 -101
  42. package/dist/response.mjs +0 -74
  43. package/dist/server.d.mts +0 -10
  44. package/dist/server.d.ts +0 -10
  45. package/dist/server.js +0 -626
  46. package/dist/server.mjs +0 -590
  47. package/dist/types.d.mts +0 -44
  48. package/dist/types.d.ts +0 -44
  49. package/dist/types.js +0 -18
  50. package/dist/types.mjs +0 -0
  51. package/dist/utils/response/constants.d.mts +0 -3
  52. package/dist/utils/response/constants.d.ts +0 -3
  53. package/dist/utils/response/constants.js +0 -30
  54. package/dist/utils/response/constants.mjs +0 -5
  55. package/dist/utils.d.mts +0 -9
  56. package/dist/utils.d.ts +0 -9
  57. package/dist/utils.js +0 -99
  58. package/dist/utils.mjs +0 -71
@@ -1,152 +1,134 @@
1
- // src/serve-static.ts
1
+ import { Readable } from "node:stream";
2
2
  import { getMimeType } from "hono/utils/mime";
3
- import { createReadStream, statSync, existsSync } from "fs";
4
- import { join } from "path";
5
- import { versions } from "process";
6
- import { Readable } from "stream";
7
- var 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
- var ENCODINGS = {
9
- br: ".br",
10
- zstd: ".zst",
11
- gzip: ".gz"
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
- var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
14
- var pr54206Applied = () => {
15
- const [major, minor] = versions.node.split(".").map((component) => parseInt(component));
16
- return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
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
- var useReadableToWeb = pr54206Applied();
19
- var createStreamBody = (stream) => {
20
- if (useReadableToWeb) {
21
- return Readable.toWeb(stream);
22
- }
23
- const body = new ReadableStream({
24
- start(controller) {
25
- stream.on("data", (chunk) => {
26
- controller.enqueue(chunk);
27
- });
28
- stream.on("error", (err) => {
29
- controller.error(err);
30
- });
31
- stream.on("end", () => {
32
- controller.close();
33
- });
34
- },
35
- cancel() {
36
- stream.destroy();
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
- var getStats = (path) => {
42
- let stats;
43
- try {
44
- stats = statSync(path);
45
- } catch {
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
- var tryDecode = (str, decoder) => {
50
- try {
51
- return decoder(str);
52
- } catch {
53
- return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
54
- try {
55
- return decoder(match);
56
- } catch {
57
- return match;
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
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
63
- var serveStatic = (options = { root: "" }) => {
64
- const root = options.root || "";
65
- const optionPath = options.path;
66
- if (root !== "" && !existsSync(root)) {
67
- console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
68
- }
69
- return async (c, next) => {
70
- if (c.finalized) {
71
- return next();
72
- }
73
- let filename;
74
- if (optionPath) {
75
- filename = optionPath;
76
- } else {
77
- try {
78
- filename = tryDecodeURI(c.req.path);
79
- if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
80
- throw new Error();
81
- }
82
- } catch {
83
- await options.onNotFound?.(c.req.path, c);
84
- return next();
85
- }
86
- }
87
- let path = join(
88
- root,
89
- !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
90
- );
91
- let stats = getStats(path);
92
- if (stats && stats.isDirectory()) {
93
- const indexFile = options.index ?? "index.html";
94
- path = join(path, indexFile);
95
- stats = getStats(path);
96
- }
97
- if (!stats) {
98
- await options.onNotFound?.(path, c);
99
- return next();
100
- }
101
- const mimeType = getMimeType(path);
102
- c.header("Content-Type", mimeType || "application/octet-stream");
103
- if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
104
- const acceptEncodingSet = new Set(
105
- c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
106
- );
107
- for (const encoding of ENCODINGS_ORDERED_KEYS) {
108
- if (!acceptEncodingSet.has(encoding)) {
109
- continue;
110
- }
111
- const precompressedStats = getStats(path + ENCODINGS[encoding]);
112
- if (precompressedStats) {
113
- c.header("Content-Encoding", encoding);
114
- c.header("Vary", "Accept-Encoding", { append: true });
115
- stats = precompressedStats;
116
- path = path + ENCODINGS[encoding];
117
- break;
118
- }
119
- }
120
- }
121
- let result;
122
- const size = stats.size;
123
- const range = c.req.header("range") || "";
124
- if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
125
- c.header("Content-Length", size.toString());
126
- c.status(200);
127
- result = c.body(null);
128
- } else if (!range) {
129
- c.header("Content-Length", size.toString());
130
- result = c.body(createStreamBody(createReadStream(path)), 200);
131
- } else {
132
- c.header("Accept-Ranges", "bytes");
133
- c.header("Date", stats.birthtime.toUTCString());
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 };
@@ -1,3 +1,4 @@
1
+ //#region src/utils/response.d.ts
1
2
  declare const RESPONSE_ALREADY_SENT: Response;
2
-
3
- export { RESPONSE_ALREADY_SENT };
3
+ //#endregion
4
+ export { RESPONSE_ALREADY_SENT };
@@ -1,3 +1,4 @@
1
+ //#region src/utils/response.d.ts
1
2
  declare const RESPONSE_ALREADY_SENT: Response;
2
-
3
- export { RESPONSE_ALREADY_SENT };
3
+ //#endregion
4
+ export { RESPONSE_ALREADY_SENT };
@@ -1,37 +1,8 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
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
- // src/utils/response.ts
21
- var response_exports = {};
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
- // src/utils/response/constants.ts
28
- var X_ALREADY_SENT = "x-hono-already-sent";
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;
@@ -1,10 +1,7 @@
1
- // src/utils/response/constants.ts
2
- var X_ALREADY_SENT = "x-hono-already-sent";
1
+ import { t as X_ALREADY_SENT } from "../constants-DEKKqoym.mjs";
3
2
 
4
- // src/utils/response.ts
5
- var RESPONSE_ALREADY_SENT = new Response(null, {
6
- headers: { [X_ALREADY_SENT]: "true" }
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 * as http2 from 'http2';
2
- import * as http from 'http';
3
- import { Hono } from 'hono';
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 * as http2 from 'http2';
2
- import * as http from 'http';
3
- import { Hono } from 'hono';
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 };