@hono/node-server 1.2.0 → 1.2.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/dist/globals.d.mts +2 -0
- package/dist/globals.d.ts +2 -1
- package/dist/globals.js +4 -2
- package/dist/globals.mjs +1 -1
- package/dist/index.d.mts +7 -0
- package/dist/index.d.ts +7 -2
- package/dist/index.js +121 -5
- package/dist/index.mjs +105 -3
- package/dist/listener.d.mts +8 -0
- package/dist/listener.d.ts +8 -5
- package/dist/listener.js +39 -10
- package/dist/listener.mjs +26 -9
- package/dist/serve-static.d.mts +14 -0
- package/dist/serve-static.d.ts +6 -3
- package/dist/serve-static.js +122 -6
- package/dist/serve-static.mjs +116 -2
- package/dist/server.d.mts +10 -0
- package/dist/server.d.ts +10 -4
- package/dist/server.js +104 -5
- package/dist/server.mjs +89 -2
- package/dist/types.d.mts +33 -0
- package/dist/types.d.ts +17 -18
- package/dist/types.js +18 -0
- package/dist/types.mjs +0 -0
- package/dist/vercel.d.mts +7 -0
- package/dist/vercel.d.ts +7 -4
- package/dist/vercel.js +102 -3
- package/dist/vercel.mjs +86 -1
- package/package.json +6 -8
package/dist/serve-static.mjs
CHANGED
|
@@ -1,7 +1,121 @@
|
|
|
1
1
|
// src/serve-static.ts
|
|
2
2
|
import { createReadStream, existsSync, lstatSync } from "fs";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
|
|
4
|
+
// node_modules/hono/dist/utils/filepath.js
|
|
5
|
+
var getFilePath = (options) => {
|
|
6
|
+
let filename = options.filename;
|
|
7
|
+
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename))
|
|
8
|
+
return;
|
|
9
|
+
let root = options.root || "";
|
|
10
|
+
const defaultDocument = options.defaultDocument || "index.html";
|
|
11
|
+
if (filename.endsWith("/")) {
|
|
12
|
+
filename = filename.concat(defaultDocument);
|
|
13
|
+
} else if (!filename.match(/\.[a-zA-Z0-9]+$/)) {
|
|
14
|
+
filename = filename.concat("/" + defaultDocument);
|
|
15
|
+
}
|
|
16
|
+
filename = filename.replace(/^\.?[\/\\]/, "");
|
|
17
|
+
filename = filename.replace(/\\/, "/");
|
|
18
|
+
root = root.replace(/\/$/, "");
|
|
19
|
+
let path = root ? root + "/" + filename : filename;
|
|
20
|
+
path = path.replace(/^\.?\//, "");
|
|
21
|
+
return path;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// node_modules/hono/dist/utils/mime.js
|
|
25
|
+
var getMimeType = (filename) => {
|
|
26
|
+
const regexp = /\.([a-zA-Z0-9]+?)$/;
|
|
27
|
+
const match = filename.match(regexp);
|
|
28
|
+
if (!match)
|
|
29
|
+
return;
|
|
30
|
+
let mimeType = mimes[match[1]];
|
|
31
|
+
if (mimeType && mimeType.startsWith("text") || mimeType === "application/json") {
|
|
32
|
+
mimeType += "; charset=utf-8";
|
|
33
|
+
}
|
|
34
|
+
return mimeType;
|
|
35
|
+
};
|
|
36
|
+
var mimes = {
|
|
37
|
+
aac: "audio/aac",
|
|
38
|
+
abw: "application/x-abiword",
|
|
39
|
+
arc: "application/x-freearc",
|
|
40
|
+
avi: "video/x-msvideo",
|
|
41
|
+
avif: "image/avif",
|
|
42
|
+
av1: "video/av1",
|
|
43
|
+
azw: "application/vnd.amazon.ebook",
|
|
44
|
+
bin: "application/octet-stream",
|
|
45
|
+
bmp: "image/bmp",
|
|
46
|
+
bz: "application/x-bzip",
|
|
47
|
+
bz2: "application/x-bzip2",
|
|
48
|
+
csh: "application/x-csh",
|
|
49
|
+
css: "text/css",
|
|
50
|
+
csv: "text/csv",
|
|
51
|
+
doc: "application/msword",
|
|
52
|
+
docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
53
|
+
eot: "application/vnd.ms-fontobject",
|
|
54
|
+
epub: "application/epub+zip",
|
|
55
|
+
gif: "image/gif",
|
|
56
|
+
gz: "application/gzip",
|
|
57
|
+
htm: "text/html",
|
|
58
|
+
html: "text/html",
|
|
59
|
+
ico: "image/x-icon",
|
|
60
|
+
ics: "text/calendar",
|
|
61
|
+
jar: "application/java-archive",
|
|
62
|
+
jpeg: "image/jpeg",
|
|
63
|
+
jpg: "image/jpeg",
|
|
64
|
+
js: "text/javascript",
|
|
65
|
+
json: "application/json",
|
|
66
|
+
jsonld: "application/ld+json",
|
|
67
|
+
map: "application/json",
|
|
68
|
+
mid: "audio/x-midi",
|
|
69
|
+
midi: "audio/x-midi",
|
|
70
|
+
mjs: "text/javascript",
|
|
71
|
+
mp3: "audio/mpeg",
|
|
72
|
+
mp4: "video/mp4",
|
|
73
|
+
mpeg: "video/mpeg",
|
|
74
|
+
mpkg: "application/vnd.apple.installer+xml",
|
|
75
|
+
odp: "application/vnd.oasis.opendocument.presentation",
|
|
76
|
+
ods: "application/vnd.oasis.opendocument.spreadsheet",
|
|
77
|
+
odt: "application/vnd.oasis.opendocument.text",
|
|
78
|
+
oga: "audio/ogg",
|
|
79
|
+
ogv: "video/ogg",
|
|
80
|
+
ogx: "application/ogg",
|
|
81
|
+
opus: "audio/opus",
|
|
82
|
+
otf: "font/otf",
|
|
83
|
+
pdf: "application/pdf",
|
|
84
|
+
php: "application/php",
|
|
85
|
+
png: "image/png",
|
|
86
|
+
ppt: "application/vnd.ms-powerpoint",
|
|
87
|
+
pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
88
|
+
rtf: "application/rtf",
|
|
89
|
+
sh: "application/x-sh",
|
|
90
|
+
svg: "image/svg+xml",
|
|
91
|
+
swf: "application/x-shockwave-flash",
|
|
92
|
+
tar: "application/x-tar",
|
|
93
|
+
tif: "image/tiff",
|
|
94
|
+
tiff: "image/tiff",
|
|
95
|
+
ts: "video/mp2t",
|
|
96
|
+
ttf: "font/ttf",
|
|
97
|
+
txt: "text/plain",
|
|
98
|
+
vsd: "application/vnd.visio",
|
|
99
|
+
wasm: "application/wasm",
|
|
100
|
+
webm: "video/webm",
|
|
101
|
+
weba: "audio/webm",
|
|
102
|
+
webp: "image/webp",
|
|
103
|
+
woff: "font/woff",
|
|
104
|
+
woff2: "font/woff2",
|
|
105
|
+
xhtml: "application/xhtml+xml",
|
|
106
|
+
xls: "application/vnd.ms-excel",
|
|
107
|
+
xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
108
|
+
xml: "application/xml",
|
|
109
|
+
xul: "application/vnd.mozilla.xul+xml",
|
|
110
|
+
zip: "application/zip",
|
|
111
|
+
"3gp": "video/3gpp",
|
|
112
|
+
"3g2": "video/3gpp2",
|
|
113
|
+
"7z": "application/x-7z-compressed",
|
|
114
|
+
gltf: "model/gltf+json",
|
|
115
|
+
glb: "model/gltf-binary"
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
// src/serve-static.ts
|
|
5
119
|
var createStreamBody = (stream) => {
|
|
6
120
|
const body = new ReadableStream({
|
|
7
121
|
start(controller) {
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AddressInfo } from 'node:net';
|
|
2
|
+
import { Options, ServerType } from './types.mjs';
|
|
3
|
+
import 'node:http';
|
|
4
|
+
import 'node:https';
|
|
5
|
+
import 'node:http2';
|
|
6
|
+
|
|
7
|
+
declare const createAdaptorServer: (options: Options) => ServerType;
|
|
8
|
+
declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType;
|
|
9
|
+
|
|
10
|
+
export { createAdaptorServer, serve };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { AddressInfo } from 'node:net';
|
|
2
|
+
import { Options, ServerType } from './types.js';
|
|
3
|
+
import 'node:http';
|
|
4
|
+
import 'node:https';
|
|
5
|
+
import 'node:http2';
|
|
6
|
+
|
|
7
|
+
declare const createAdaptorServer: (options: Options) => ServerType;
|
|
8
|
+
declare const serve: (options: Options, listeningListener?: ((info: AddressInfo) => void) | undefined) => ServerType;
|
|
9
|
+
|
|
10
|
+
export { createAdaptorServer, serve };
|
package/dist/server.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,23 +17,120 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/server.ts
|
|
19
31
|
var server_exports = {};
|
|
20
32
|
__export(server_exports, {
|
|
21
33
|
createAdaptorServer: () => createAdaptorServer,
|
|
22
34
|
serve: () => serve
|
|
23
35
|
});
|
|
24
36
|
module.exports = __toCommonJS(server_exports);
|
|
25
|
-
var import_node_http = require("
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
var import_node_http = require("http");
|
|
38
|
+
|
|
39
|
+
// src/listener.ts
|
|
40
|
+
var import_node_stream = require("stream");
|
|
41
|
+
var import_promises = require("stream/promises");
|
|
42
|
+
|
|
43
|
+
// src/globals.ts
|
|
44
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
45
|
+
var webFetch = global.fetch;
|
|
46
|
+
if (typeof global.crypto === "undefined") {
|
|
47
|
+
global.crypto = import_node_crypto.default;
|
|
48
|
+
}
|
|
49
|
+
global.fetch = (info, init) => {
|
|
50
|
+
init = {
|
|
51
|
+
// Disable compression handling so people can return the result of a fetch
|
|
52
|
+
// directly in the loader without messing with the Content-Encoding header.
|
|
53
|
+
compress: false,
|
|
54
|
+
...init
|
|
55
|
+
};
|
|
56
|
+
return webFetch(info, init);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// src/listener.ts
|
|
60
|
+
var regBuffer = /^no$/i;
|
|
61
|
+
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
62
|
+
var getRequestListener = (fetchCallback) => {
|
|
63
|
+
return async (incoming, outgoing) => {
|
|
64
|
+
const method = incoming.method || "GET";
|
|
65
|
+
const url = `http://${incoming.headers.host}${incoming.url}`;
|
|
66
|
+
const headerRecord = [];
|
|
67
|
+
const len = incoming.rawHeaders.length;
|
|
68
|
+
for (let i = 0; i < len; i += 2) {
|
|
69
|
+
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
70
|
+
}
|
|
71
|
+
const init = {
|
|
72
|
+
method,
|
|
73
|
+
headers: headerRecord
|
|
74
|
+
};
|
|
75
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
76
|
+
init.body = import_node_stream.Readable.toWeb(incoming);
|
|
77
|
+
init.duplex = "half";
|
|
78
|
+
}
|
|
79
|
+
let res;
|
|
80
|
+
try {
|
|
81
|
+
res = await fetchCallback(new Request(url.toString(), init));
|
|
82
|
+
} catch (e) {
|
|
83
|
+
res = new Response(null, { status: 500 });
|
|
84
|
+
if (e instanceof Error) {
|
|
85
|
+
if (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") {
|
|
86
|
+
res = new Response(null, { status: 504 });
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const resHeaderRecord = {};
|
|
91
|
+
for (const [k, v] of res.headers) {
|
|
92
|
+
resHeaderRecord[k] = v;
|
|
93
|
+
if (k === "set-cookie") {
|
|
94
|
+
outgoing.setHeader(k, res.headers.getSetCookie(k));
|
|
95
|
+
} else {
|
|
96
|
+
outgoing.setHeader(k, v);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
outgoing.statusCode = res.status;
|
|
100
|
+
if (res.body) {
|
|
101
|
+
try {
|
|
102
|
+
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
|
|
103
|
+
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
|
|
104
|
+
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
|
|
105
|
+
} else {
|
|
106
|
+
const text = await res.text();
|
|
107
|
+
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
|
|
108
|
+
outgoing.end(text);
|
|
109
|
+
}
|
|
110
|
+
} catch (e) {
|
|
111
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
112
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
113
|
+
console.info("The user aborted a request.");
|
|
114
|
+
} else {
|
|
115
|
+
console.error(e);
|
|
116
|
+
outgoing.destroy(err);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
outgoing.end();
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// src/server.ts
|
|
126
|
+
var createAdaptorServer = (options) => {
|
|
28
127
|
const fetchCallback = options.fetch;
|
|
29
|
-
const requestListener =
|
|
128
|
+
const requestListener = getRequestListener(fetchCallback);
|
|
30
129
|
const createServer = options.createServer || import_node_http.createServer;
|
|
31
130
|
const server = createServer(options.serverOptions || {}, requestListener);
|
|
32
131
|
return server;
|
|
33
132
|
};
|
|
34
|
-
|
|
133
|
+
var serve = (options, listeningListener) => {
|
|
35
134
|
const server = createAdaptorServer(options);
|
|
36
135
|
server.listen(options?.port ?? 3e3, options.hostname ?? "0.0.0.0", () => {
|
|
37
136
|
const serverInfo = server.address();
|
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,93 @@
|
|
|
1
1
|
// src/server.ts
|
|
2
|
-
import { createServer as createServerHTTP } from "
|
|
3
|
-
|
|
2
|
+
import { createServer as createServerHTTP } from "http";
|
|
3
|
+
|
|
4
|
+
// src/listener.ts
|
|
5
|
+
import { Readable } from "stream";
|
|
6
|
+
import { pipeline } from "stream/promises";
|
|
7
|
+
|
|
8
|
+
// src/globals.ts
|
|
9
|
+
import crypto from "crypto";
|
|
10
|
+
var webFetch = global.fetch;
|
|
11
|
+
if (typeof global.crypto === "undefined") {
|
|
12
|
+
global.crypto = crypto;
|
|
13
|
+
}
|
|
14
|
+
global.fetch = (info, init) => {
|
|
15
|
+
init = {
|
|
16
|
+
// Disable compression handling so people can return the result of a fetch
|
|
17
|
+
// directly in the loader without messing with the Content-Encoding header.
|
|
18
|
+
compress: false,
|
|
19
|
+
...init
|
|
20
|
+
};
|
|
21
|
+
return webFetch(info, init);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// src/listener.ts
|
|
25
|
+
var regBuffer = /^no$/i;
|
|
26
|
+
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
27
|
+
var getRequestListener = (fetchCallback) => {
|
|
28
|
+
return async (incoming, outgoing) => {
|
|
29
|
+
const method = incoming.method || "GET";
|
|
30
|
+
const url = `http://${incoming.headers.host}${incoming.url}`;
|
|
31
|
+
const headerRecord = [];
|
|
32
|
+
const len = incoming.rawHeaders.length;
|
|
33
|
+
for (let i = 0; i < len; i += 2) {
|
|
34
|
+
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
35
|
+
}
|
|
36
|
+
const init = {
|
|
37
|
+
method,
|
|
38
|
+
headers: headerRecord
|
|
39
|
+
};
|
|
40
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
41
|
+
init.body = Readable.toWeb(incoming);
|
|
42
|
+
init.duplex = "half";
|
|
43
|
+
}
|
|
44
|
+
let res;
|
|
45
|
+
try {
|
|
46
|
+
res = await fetchCallback(new Request(url.toString(), init));
|
|
47
|
+
} catch (e) {
|
|
48
|
+
res = new Response(null, { status: 500 });
|
|
49
|
+
if (e instanceof Error) {
|
|
50
|
+
if (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") {
|
|
51
|
+
res = new Response(null, { status: 504 });
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const resHeaderRecord = {};
|
|
56
|
+
for (const [k, v] of res.headers) {
|
|
57
|
+
resHeaderRecord[k] = v;
|
|
58
|
+
if (k === "set-cookie") {
|
|
59
|
+
outgoing.setHeader(k, res.headers.getSetCookie(k));
|
|
60
|
+
} else {
|
|
61
|
+
outgoing.setHeader(k, v);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
outgoing.statusCode = res.status;
|
|
65
|
+
if (res.body) {
|
|
66
|
+
try {
|
|
67
|
+
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
|
|
68
|
+
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
|
|
69
|
+
await pipeline(Readable.fromWeb(res.body), outgoing);
|
|
70
|
+
} else {
|
|
71
|
+
const text = await res.text();
|
|
72
|
+
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
|
|
73
|
+
outgoing.end(text);
|
|
74
|
+
}
|
|
75
|
+
} catch (e) {
|
|
76
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
77
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
78
|
+
console.info("The user aborted a request.");
|
|
79
|
+
} else {
|
|
80
|
+
console.error(e);
|
|
81
|
+
outgoing.destroy(err);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
} else {
|
|
85
|
+
outgoing.end();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
// src/server.ts
|
|
4
91
|
var createAdaptorServer = (options) => {
|
|
5
92
|
const fetchCallback = options.fetch;
|
|
6
93
|
const requestListener = getRequestListener(fetchCallback);
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
|
|
2
|
+
import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
|
|
3
|
+
import { Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
|
|
4
|
+
|
|
5
|
+
declare type FetchCallback = (request: Request) => Promise<unknown> | unknown;
|
|
6
|
+
declare type NextHandlerOption = {
|
|
7
|
+
fetch: FetchCallback;
|
|
8
|
+
};
|
|
9
|
+
declare type ServerType = Server | Http2Server | Http2SecureServer;
|
|
10
|
+
declare type createHttpOptions = {
|
|
11
|
+
serverOptions?: ServerOptions$1;
|
|
12
|
+
createServer?: typeof createServer;
|
|
13
|
+
};
|
|
14
|
+
declare type createHttpsOptions = {
|
|
15
|
+
serverOptions?: ServerOptions$2;
|
|
16
|
+
createServer?: typeof createServer$1;
|
|
17
|
+
};
|
|
18
|
+
declare type createHttp2Options = {
|
|
19
|
+
serverOptions?: ServerOptions$3;
|
|
20
|
+
createServer?: typeof createServer$2;
|
|
21
|
+
};
|
|
22
|
+
declare type createSecureHttp2Options = {
|
|
23
|
+
serverOptions?: SecureServerOptions;
|
|
24
|
+
createServer?: typeof createSecureServer;
|
|
25
|
+
};
|
|
26
|
+
declare type ServerOptions = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
|
27
|
+
declare type Options = {
|
|
28
|
+
fetch: FetchCallback;
|
|
29
|
+
port?: number;
|
|
30
|
+
hostname?: string;
|
|
31
|
+
} & ServerOptions;
|
|
32
|
+
|
|
33
|
+
export { FetchCallback, NextHandlerOption, Options, ServerType };
|
package/dist/types.d.ts
CHANGED
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare type FetchCallback = (request: Request) => Promise<unknown> | unknown;
|
|
8
|
-
export declare type NextHandlerOption = {
|
|
1
|
+
import { Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
|
|
2
|
+
import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
|
|
3
|
+
import { Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
|
|
4
|
+
|
|
5
|
+
declare type FetchCallback = (request: Request) => Promise<unknown> | unknown;
|
|
6
|
+
declare type NextHandlerOption = {
|
|
9
7
|
fetch: FetchCallback;
|
|
10
8
|
};
|
|
11
|
-
|
|
9
|
+
declare type ServerType = Server | Http2Server | Http2SecureServer;
|
|
12
10
|
declare type createHttpOptions = {
|
|
13
|
-
serverOptions?:
|
|
11
|
+
serverOptions?: ServerOptions$1;
|
|
14
12
|
createServer?: typeof createServer;
|
|
15
13
|
};
|
|
16
14
|
declare type createHttpsOptions = {
|
|
17
|
-
serverOptions?:
|
|
18
|
-
createServer?: typeof
|
|
15
|
+
serverOptions?: ServerOptions$2;
|
|
16
|
+
createServer?: typeof createServer$1;
|
|
19
17
|
};
|
|
20
18
|
declare type createHttp2Options = {
|
|
21
|
-
serverOptions?:
|
|
22
|
-
createServer?: typeof
|
|
19
|
+
serverOptions?: ServerOptions$3;
|
|
20
|
+
createServer?: typeof createServer$2;
|
|
23
21
|
};
|
|
24
22
|
declare type createSecureHttp2Options = {
|
|
25
|
-
serverOptions?:
|
|
26
|
-
createServer?: typeof
|
|
23
|
+
serverOptions?: SecureServerOptions;
|
|
24
|
+
createServer?: typeof createSecureServer;
|
|
27
25
|
};
|
|
28
26
|
declare type ServerOptions = createHttpOptions | createHttpsOptions | createHttp2Options | createSecureHttp2Options;
|
|
29
|
-
|
|
27
|
+
declare type Options = {
|
|
30
28
|
fetch: FetchCallback;
|
|
31
29
|
port?: number;
|
|
32
30
|
hostname?: string;
|
|
33
31
|
} & ServerOptions;
|
|
34
|
-
|
|
32
|
+
|
|
33
|
+
export { FetchCallback, NextHandlerOption, Options, ServerType };
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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 __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/types.ts
|
|
17
|
+
var types_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/types.mjs
ADDED
|
File without changes
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as http2 from 'http2';
|
|
2
|
+
import * as http from 'http';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse<http.IncomingMessage> | http2.Http2ServerResponse) => Promise<void>;
|
|
6
|
+
|
|
7
|
+
export { handle };
|
package/dist/vercel.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
|
|
1
|
+
import * as http2 from 'http2';
|
|
2
|
+
import * as http from 'http';
|
|
3
|
+
import { Hono } from 'hono';
|
|
4
|
+
|
|
5
|
+
declare const handle: (app: Hono<any, any, any>) => (incoming: http.IncomingMessage | http2.Http2ServerRequest, outgoing: http.ServerResponse<http.IncomingMessage> | http2.Http2ServerResponse) => Promise<void>;
|
|
6
|
+
|
|
7
|
+
export { handle };
|
package/dist/vercel.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,15 +17,112 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/vercel.ts
|
|
19
31
|
var vercel_exports = {};
|
|
20
32
|
__export(vercel_exports, {
|
|
21
33
|
handle: () => handle
|
|
22
34
|
});
|
|
23
35
|
module.exports = __toCommonJS(vercel_exports);
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
36
|
+
|
|
37
|
+
// src/listener.ts
|
|
38
|
+
var import_node_stream = require("stream");
|
|
39
|
+
var import_promises = require("stream/promises");
|
|
40
|
+
|
|
41
|
+
// src/globals.ts
|
|
42
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
43
|
+
var webFetch = global.fetch;
|
|
44
|
+
if (typeof global.crypto === "undefined") {
|
|
45
|
+
global.crypto = import_node_crypto.default;
|
|
46
|
+
}
|
|
47
|
+
global.fetch = (info, init) => {
|
|
48
|
+
init = {
|
|
49
|
+
// Disable compression handling so people can return the result of a fetch
|
|
50
|
+
// directly in the loader without messing with the Content-Encoding header.
|
|
51
|
+
compress: false,
|
|
52
|
+
...init
|
|
53
|
+
};
|
|
54
|
+
return webFetch(info, init);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/listener.ts
|
|
58
|
+
var regBuffer = /^no$/i;
|
|
59
|
+
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
60
|
+
var getRequestListener = (fetchCallback) => {
|
|
61
|
+
return async (incoming, outgoing) => {
|
|
62
|
+
const method = incoming.method || "GET";
|
|
63
|
+
const url = `http://${incoming.headers.host}${incoming.url}`;
|
|
64
|
+
const headerRecord = [];
|
|
65
|
+
const len = incoming.rawHeaders.length;
|
|
66
|
+
for (let i = 0; i < len; i += 2) {
|
|
67
|
+
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
68
|
+
}
|
|
69
|
+
const init = {
|
|
70
|
+
method,
|
|
71
|
+
headers: headerRecord
|
|
72
|
+
};
|
|
73
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
74
|
+
init.body = import_node_stream.Readable.toWeb(incoming);
|
|
75
|
+
init.duplex = "half";
|
|
76
|
+
}
|
|
77
|
+
let res;
|
|
78
|
+
try {
|
|
79
|
+
res = await fetchCallback(new Request(url.toString(), init));
|
|
80
|
+
} catch (e) {
|
|
81
|
+
res = new Response(null, { status: 500 });
|
|
82
|
+
if (e instanceof Error) {
|
|
83
|
+
if (e.name === "TimeoutError" || e.constructor.name === "TimeoutError") {
|
|
84
|
+
res = new Response(null, { status: 504 });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const resHeaderRecord = {};
|
|
89
|
+
for (const [k, v] of res.headers) {
|
|
90
|
+
resHeaderRecord[k] = v;
|
|
91
|
+
if (k === "set-cookie") {
|
|
92
|
+
outgoing.setHeader(k, res.headers.getSetCookie(k));
|
|
93
|
+
} else {
|
|
94
|
+
outgoing.setHeader(k, v);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
outgoing.statusCode = res.status;
|
|
98
|
+
if (res.body) {
|
|
99
|
+
try {
|
|
100
|
+
if (resHeaderRecord["transfer-encoding"] || resHeaderRecord["content-encoding"] || resHeaderRecord["content-length"] || // nginx buffering variant
|
|
101
|
+
regBuffer.test(resHeaderRecord["x-accel-buffering"]) || !regContentType.test(resHeaderRecord["content-type"])) {
|
|
102
|
+
await (0, import_promises.pipeline)(import_node_stream.Readable.fromWeb(res.body), outgoing);
|
|
103
|
+
} else {
|
|
104
|
+
const text = await res.text();
|
|
105
|
+
outgoing.setHeader("Content-Length", Buffer.byteLength(text));
|
|
106
|
+
outgoing.end(text);
|
|
107
|
+
}
|
|
108
|
+
} catch (e) {
|
|
109
|
+
const err = e instanceof Error ? e : new Error("unknown error", { cause: e });
|
|
110
|
+
if (err.code === "ERR_STREAM_PREMATURE_CLOSE") {
|
|
111
|
+
console.info("The user aborted a request.");
|
|
112
|
+
} else {
|
|
113
|
+
console.error(e);
|
|
114
|
+
outgoing.destroy(err);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
} else {
|
|
118
|
+
outgoing.end();
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
// src/vercel.ts
|
|
124
|
+
var handle = (app) => {
|
|
125
|
+
return getRequestListener(app.fetch);
|
|
27
126
|
};
|
|
28
127
|
// Annotate the CommonJS export names for ESM import in node:
|
|
29
128
|
0 && (module.exports = {
|