@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.
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 -613
  11. package/dist/index.mjs +24 -573
  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 -585
  25. package/dist/vercel.mjs +6 -548
  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 -581
  34. package/dist/listener.mjs +0 -546
  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 -99
  42. package/dist/response.mjs +0 -72
  43. package/dist/server.d.mts +0 -10
  44. package/dist/server.d.ts +0 -10
  45. package/dist/server.js +0 -607
  46. package/dist/server.mjs +0 -571
  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,17 +1,18 @@
1
- import { Env, Context, MiddlewareHandler } from 'hono';
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
- * Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
6
- */
7
- root?: string;
8
- path?: string;
9
- index?: string;
10
- precompressed?: boolean;
11
- rewriteRequestPath?: (path: string, c: Context<E>) => string;
12
- onFound?: (path: string, c: Context<E>) => void | Promise<void>;
13
- onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
5
+ /**
6
+ * Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
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 { type ServeStaticOptions, serveStatic };
17
+ //#endregion
18
+ export { ServeStaticOptions, serveStatic };
@@ -1,17 +1,18 @@
1
- import { Env, Context, MiddlewareHandler } from 'hono';
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
- * Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
6
- */
7
- root?: string;
8
- path?: string;
9
- index?: string;
10
- precompressed?: boolean;
11
- rewriteRequestPath?: (path: string, c: Context<E>) => string;
12
- onFound?: (path: string, c: Context<E>) => void | Promise<void>;
13
- onNotFound?: (path: string, c: Context<E>) => void | Promise<void>;
5
+ /**
6
+ * Root path, relative to current working directory from which the app was started. Absolute paths are not supported.
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 { type ServeStaticOptions, serveStatic };
17
+ //#endregion
18
+ export { ServeStaticOptions, serveStatic };
@@ -1,177 +1,135 @@
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
+ let node_stream = require("node:stream");
3
+ let hono_utils_mime = require("hono/utils/mime");
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
6
+ let node_process = require("node:process");
19
7
 
20
- // src/serve-static.ts
21
- var serve_static_exports = {};
22
- __export(serve_static_exports, {
23
- serveStatic: () => serveStatic
24
- });
25
- module.exports = __toCommonJS(serve_static_exports);
26
- var import_mime = require("hono/utils/mime");
27
- var import_node_fs = require("fs");
28
- var import_node_path = require("path");
29
- var import_node_process = require("process");
30
- var import_node_stream = require("stream");
31
- 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;
32
- var ENCODINGS = {
33
- br: ".br",
34
- zstd: ".zst",
35
- gzip: ".gz"
8
+ //#region src/serve-static.ts
9
+ 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;
10
+ const ENCODINGS = {
11
+ br: ".br",
12
+ zstd: ".zst",
13
+ gzip: ".gz"
36
14
  };
37
- var ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
38
- var pr54206Applied = () => {
39
- const [major, minor] = import_node_process.versions.node.split(".").map((component) => parseInt(component));
40
- return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
15
+ const ENCODINGS_ORDERED_KEYS = Object.keys(ENCODINGS);
16
+ const pr54206Applied = () => {
17
+ const [major, minor] = node_process.versions.node.split(".").map((component) => parseInt(component));
18
+ return major >= 23 || major === 22 && minor >= 7 || major === 20 && minor >= 18;
41
19
  };
42
- var useReadableToWeb = pr54206Applied();
43
- var createStreamBody = (stream) => {
44
- if (useReadableToWeb) {
45
- return import_node_stream.Readable.toWeb(stream);
46
- }
47
- const body = new ReadableStream({
48
- start(controller) {
49
- stream.on("data", (chunk) => {
50
- controller.enqueue(chunk);
51
- });
52
- stream.on("error", (err) => {
53
- controller.error(err);
54
- });
55
- stream.on("end", () => {
56
- controller.close();
57
- });
58
- },
59
- cancel() {
60
- stream.destroy();
61
- }
62
- });
63
- return body;
20
+ const useReadableToWeb = pr54206Applied();
21
+ const createStreamBody = (stream) => {
22
+ if (useReadableToWeb) return node_stream.Readable.toWeb(stream);
23
+ return 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
+ });
64
39
  };
65
- var getStats = (path) => {
66
- let stats;
67
- try {
68
- stats = (0, import_node_fs.statSync)(path);
69
- } catch {
70
- }
71
- return stats;
40
+ const getStats = (path) => {
41
+ let stats;
42
+ try {
43
+ stats = (0, node_fs.statSync)(path);
44
+ } catch {}
45
+ return stats;
72
46
  };
73
- var tryDecode = (str, decoder) => {
74
- try {
75
- return decoder(str);
76
- } catch {
77
- return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
78
- try {
79
- return decoder(match);
80
- } catch {
81
- return match;
82
- }
83
- });
84
- }
47
+ const tryDecode = (str, decoder) => {
48
+ try {
49
+ return decoder(str);
50
+ } catch {
51
+ return str.replace(/(?:%[0-9A-Fa-f]{2})+/g, (match) => {
52
+ try {
53
+ return decoder(match);
54
+ } catch {
55
+ return match;
56
+ }
57
+ });
58
+ }
85
59
  };
86
- var tryDecodeURI = (str) => tryDecode(str, decodeURI);
87
- var serveStatic = (options = { root: "" }) => {
88
- const root = options.root || "";
89
- const optionPath = options.path;
90
- if (root !== "" && !(0, import_node_fs.existsSync)(root)) {
91
- console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
92
- }
93
- return async (c, next) => {
94
- if (c.finalized) {
95
- return next();
96
- }
97
- let filename;
98
- if (optionPath) {
99
- filename = optionPath;
100
- } else {
101
- try {
102
- filename = tryDecodeURI(c.req.path);
103
- if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
104
- throw new Error();
105
- }
106
- } catch {
107
- await options.onNotFound?.(c.req.path, c);
108
- return next();
109
- }
110
- }
111
- let path = (0, import_node_path.join)(
112
- root,
113
- !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
114
- );
115
- let stats = getStats(path);
116
- if (stats && stats.isDirectory()) {
117
- const indexFile = options.index ?? "index.html";
118
- path = (0, import_node_path.join)(path, indexFile);
119
- stats = getStats(path);
120
- }
121
- if (!stats) {
122
- await options.onNotFound?.(path, c);
123
- return next();
124
- }
125
- const mimeType = (0, import_mime.getMimeType)(path);
126
- c.header("Content-Type", mimeType || "application/octet-stream");
127
- if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
128
- const acceptEncodingSet = new Set(
129
- c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim())
130
- );
131
- for (const encoding of ENCODINGS_ORDERED_KEYS) {
132
- if (!acceptEncodingSet.has(encoding)) {
133
- continue;
134
- }
135
- const precompressedStats = getStats(path + ENCODINGS[encoding]);
136
- if (precompressedStats) {
137
- c.header("Content-Encoding", encoding);
138
- c.header("Vary", "Accept-Encoding", { append: true });
139
- stats = precompressedStats;
140
- path = path + ENCODINGS[encoding];
141
- break;
142
- }
143
- }
144
- }
145
- let result;
146
- const size = stats.size;
147
- const range = c.req.header("range") || "";
148
- if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
149
- c.header("Content-Length", size.toString());
150
- c.status(200);
151
- result = c.body(null);
152
- } else if (!range) {
153
- c.header("Content-Length", size.toString());
154
- result = c.body(createStreamBody((0, import_node_fs.createReadStream)(path)), 200);
155
- } else {
156
- c.header("Accept-Ranges", "bytes");
157
- c.header("Date", stats.birthtime.toUTCString());
158
- const parts = range.replace(/bytes=/, "").split("-", 2);
159
- const start = parseInt(parts[0], 10) || 0;
160
- let end = parseInt(parts[1], 10) || size - 1;
161
- if (size < end - start + 1) {
162
- end = size - 1;
163
- }
164
- const chunksize = end - start + 1;
165
- const stream = (0, import_node_fs.createReadStream)(path, { start, end });
166
- c.header("Content-Length", chunksize.toString());
167
- c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
168
- result = c.body(createStreamBody(stream), 206);
169
- }
170
- await options.onFound?.(path, c);
171
- return result;
172
- };
60
+ const tryDecodeURI = (str) => tryDecode(str, decodeURI);
61
+ const serveStatic = (options = { root: "" }) => {
62
+ const root = options.root || "";
63
+ const optionPath = options.path;
64
+ if (root !== "" && !(0, node_fs.existsSync)(root)) console.error(`serveStatic: root path '${root}' is not found, are you sure it's correct?`);
65
+ return async (c, next) => {
66
+ if (c.finalized) return next();
67
+ let filename;
68
+ if (optionPath) filename = optionPath;
69
+ else try {
70
+ filename = tryDecodeURI(c.req.path);
71
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) throw new Error();
72
+ } catch {
73
+ await options.onNotFound?.(c.req.path, c);
74
+ return next();
75
+ }
76
+ let path = (0, node_path.join)(root, !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename);
77
+ let stats = getStats(path);
78
+ if (stats && stats.isDirectory()) {
79
+ const indexFile = options.index ?? "index.html";
80
+ path = (0, node_path.join)(path, indexFile);
81
+ stats = getStats(path);
82
+ }
83
+ if (!stats) {
84
+ await options.onNotFound?.(path, c);
85
+ return next();
86
+ }
87
+ const mimeType = (0, hono_utils_mime.getMimeType)(path);
88
+ c.header("Content-Type", mimeType || "application/octet-stream");
89
+ if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
90
+ const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
91
+ for (const encoding of ENCODINGS_ORDERED_KEYS) {
92
+ if (!acceptEncodingSet.has(encoding)) continue;
93
+ const precompressedStats = getStats(path + ENCODINGS[encoding]);
94
+ if (precompressedStats) {
95
+ c.header("Content-Encoding", encoding);
96
+ c.header("Vary", "Accept-Encoding", { append: true });
97
+ stats = precompressedStats;
98
+ path = path + ENCODINGS[encoding];
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ let result;
104
+ const size = stats.size;
105
+ const range = c.req.header("range") || "";
106
+ if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
107
+ c.header("Content-Length", size.toString());
108
+ c.status(200);
109
+ result = c.body(null);
110
+ } else if (!range) {
111
+ c.header("Content-Length", size.toString());
112
+ result = c.body(createStreamBody((0, node_fs.createReadStream)(path)), 200);
113
+ } else {
114
+ c.header("Accept-Ranges", "bytes");
115
+ c.header("Date", stats.birthtime.toUTCString());
116
+ const parts = range.replace(/bytes=/, "").split("-", 2);
117
+ const start = parseInt(parts[0], 10) || 0;
118
+ let end = parseInt(parts[1], 10) || size - 1;
119
+ if (size < end - start + 1) end = size - 1;
120
+ const chunksize = end - start + 1;
121
+ const stream = (0, node_fs.createReadStream)(path, {
122
+ start,
123
+ end
124
+ });
125
+ c.header("Content-Length", chunksize.toString());
126
+ c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
127
+ result = c.body(createStreamBody(stream), 206);
128
+ }
129
+ await options.onFound?.(path, c);
130
+ return result;
131
+ };
173
132
  };
174
- // Annotate the CommonJS export names for ESM import in node:
175
- 0 && (module.exports = {
176
- serveStatic
177
- });
133
+
134
+ //#endregion
135
+ exports.serveStatic = serveStatic;