@hono/node-server 1.19.14 → 2.0.0-rc.2
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 +56 -18
- package/dist/conninfo.cjs +22 -0
- package/dist/{conninfo.d.ts → conninfo.d.cts} +4 -3
- package/dist/conninfo.d.mts +4 -3
- package/dist/conninfo.mjs +19 -16
- package/dist/constants-BLSFu_RU.mjs +5 -0
- package/dist/constants-BXAKTxRC.cjs +11 -0
- package/dist/index.cjs +1006 -0
- package/dist/index.d.cts +73 -0
- package/dist/index.d.mts +73 -8
- package/dist/index.mjs +976 -637
- package/dist/serve-static.cjs +135 -0
- package/dist/serve-static.d.cts +18 -0
- package/dist/serve-static.d.mts +14 -13
- package/dist/serve-static.mjs +127 -145
- package/dist/utils/response.cjs +8 -0
- package/dist/utils/response.d.cts +4 -0
- package/dist/utils/response.d.mts +3 -2
- package/dist/utils/response.mjs +6 -9
- package/package.json +53 -40
- package/dist/conninfo.js +0 -42
- 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/index.d.ts +0 -8
- package/dist/index.js +0 -702
- package/dist/listener.d.mts +0 -13
- package/dist/listener.d.ts +0 -13
- package/dist/listener.js +0 -670
- package/dist/listener.mjs +0 -635
- package/dist/request.d.mts +0 -25
- package/dist/request.d.ts +0 -25
- package/dist/request.js +0 -238
- package/dist/request.mjs +0 -206
- package/dist/response.d.mts +0 -26
- package/dist/response.d.ts +0 -26
- package/dist/response.js +0 -112
- package/dist/response.mjs +0 -85
- package/dist/serve-static.d.ts +0 -17
- package/dist/serve-static.js +0 -177
- package/dist/server.d.mts +0 -10
- package/dist/server.d.ts +0 -10
- package/dist/server.js +0 -696
- package/dist/server.mjs +0 -660
- 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/response.d.ts +0 -3
- package/dist/utils/response.js +0 -37
- 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/vercel.d.mts +0 -7
- package/dist/vercel.d.ts +0 -7
- package/dist/vercel.js +0 -677
- package/dist/vercel.mjs +0 -640
package/dist/serve-static.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Env, Context, MiddlewareHandler } from 'hono';
|
|
2
|
-
|
|
3
|
-
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>;
|
|
14
|
-
};
|
|
15
|
-
declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
|
|
16
|
-
|
|
17
|
-
export { type ServeStaticOptions, serveStatic };
|
package/dist/serve-static.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
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);
|
|
19
|
-
|
|
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"
|
|
36
|
-
};
|
|
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;
|
|
41
|
-
};
|
|
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;
|
|
64
|
-
};
|
|
65
|
-
var getStats = (path) => {
|
|
66
|
-
let stats;
|
|
67
|
-
try {
|
|
68
|
-
stats = (0, import_node_fs.statSync)(path);
|
|
69
|
-
} catch {
|
|
70
|
-
}
|
|
71
|
-
return stats;
|
|
72
|
-
};
|
|
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
|
-
}
|
|
85
|
-
};
|
|
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 (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}/.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
|
-
};
|
|
173
|
-
};
|
|
174
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
175
|
-
0 && (module.exports = {
|
|
176
|
-
serveStatic
|
|
177
|
-
});
|
package/dist/server.d.mts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AddressInfo } from 'node:net';
|
|
2
|
-
import { Options, ServerType } from './types.mjs';
|
|
3
|
-
import 'node:http';
|
|
4
|
-
import 'node:http2';
|
|
5
|
-
import 'node:https';
|
|
6
|
-
|
|
7
|
-
declare const createAdaptorServer: (options: Options) => ServerType;
|
|
8
|
-
declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
|
|
9
|
-
|
|
10
|
-
export { createAdaptorServer, serve };
|
package/dist/server.d.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { AddressInfo } from 'node:net';
|
|
2
|
-
import { Options, ServerType } from './types.js';
|
|
3
|
-
import 'node:http';
|
|
4
|
-
import 'node:http2';
|
|
5
|
-
import 'node:https';
|
|
6
|
-
|
|
7
|
-
declare const createAdaptorServer: (options: Options) => ServerType;
|
|
8
|
-
declare const serve: (options: Options, listeningListener?: (info: AddressInfo) => void) => ServerType;
|
|
9
|
-
|
|
10
|
-
export { createAdaptorServer, serve };
|