@hono/node-server 1.3.3 → 1.3.4
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +76 -68
- package/dist/index.mjs +76 -68
- package/dist/listener.js +76 -68
- package/dist/listener.mjs +76 -68
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js +76 -68
- package/dist/server.mjs +76 -68
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/vercel.js +76 -68
- package/dist/vercel.mjs +76 -68
- package/package.json +7 -3
package/dist/vercel.js
CHANGED
|
@@ -34,8 +34,71 @@ __export(vercel_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(vercel_exports);
|
|
36
36
|
|
|
37
|
-
// src/
|
|
38
|
-
var
|
|
37
|
+
// src/request.ts
|
|
38
|
+
var import_node_stream = require("stream");
|
|
39
|
+
var newRequestFromIncoming = (method, url, incoming) => {
|
|
40
|
+
const headerRecord = [];
|
|
41
|
+
const len = incoming.rawHeaders.length;
|
|
42
|
+
for (let i = 0; i < len; i += 2) {
|
|
43
|
+
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
44
|
+
}
|
|
45
|
+
const init = {
|
|
46
|
+
method,
|
|
47
|
+
headers: headerRecord
|
|
48
|
+
};
|
|
49
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
50
|
+
init.body = import_node_stream.Readable.toWeb(incoming);
|
|
51
|
+
init.duplex = "half";
|
|
52
|
+
}
|
|
53
|
+
return new Request(url, init);
|
|
54
|
+
};
|
|
55
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
56
|
+
var requestCache = Symbol("requestCache");
|
|
57
|
+
var incomingKey = Symbol("incomingKey");
|
|
58
|
+
var requestPrototype = {
|
|
59
|
+
get method() {
|
|
60
|
+
return this[incomingKey].method || "GET";
|
|
61
|
+
},
|
|
62
|
+
get url() {
|
|
63
|
+
return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
|
|
64
|
+
},
|
|
65
|
+
[getRequestCache]() {
|
|
66
|
+
return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
[
|
|
70
|
+
"body",
|
|
71
|
+
"bodyUsed",
|
|
72
|
+
"cache",
|
|
73
|
+
"credentials",
|
|
74
|
+
"destination",
|
|
75
|
+
"headers",
|
|
76
|
+
"integrity",
|
|
77
|
+
"mode",
|
|
78
|
+
"redirect",
|
|
79
|
+
"referrer",
|
|
80
|
+
"referrerPolicy",
|
|
81
|
+
"signal"
|
|
82
|
+
].forEach((k) => {
|
|
83
|
+
Object.defineProperty(requestPrototype, k, {
|
|
84
|
+
get() {
|
|
85
|
+
return this[getRequestCache]()[k];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
90
|
+
Object.defineProperty(requestPrototype, k, {
|
|
91
|
+
value: function() {
|
|
92
|
+
return this[getRequestCache]()[k]();
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
Object.setPrototypeOf(requestPrototype, global.Request.prototype);
|
|
97
|
+
var newRequest = (incoming) => {
|
|
98
|
+
const req = Object.create(requestPrototype);
|
|
99
|
+
req[incomingKey] = incoming;
|
|
100
|
+
return req;
|
|
101
|
+
};
|
|
39
102
|
|
|
40
103
|
// src/utils.ts
|
|
41
104
|
function writeFromReadableStream(stream, writable) {
|
|
@@ -160,6 +223,7 @@ Object.defineProperty(global, "Response", {
|
|
|
160
223
|
});
|
|
161
224
|
|
|
162
225
|
// src/globals.ts
|
|
226
|
+
var import_node_crypto = __toESM(require("crypto"));
|
|
163
227
|
Object.defineProperty(global, "Response", {
|
|
164
228
|
value: Response2
|
|
165
229
|
});
|
|
@@ -177,72 +241,6 @@ global.fetch = (info, init) => {
|
|
|
177
241
|
return webFetch(info, init);
|
|
178
242
|
};
|
|
179
243
|
|
|
180
|
-
// src/request.ts
|
|
181
|
-
var import_node_stream = require("stream");
|
|
182
|
-
var newRequestFromIncoming = (method, url, incoming) => {
|
|
183
|
-
const headerRecord = [];
|
|
184
|
-
const len = incoming.rawHeaders.length;
|
|
185
|
-
for (let i = 0; i < len; i += 2) {
|
|
186
|
-
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
187
|
-
}
|
|
188
|
-
const init = {
|
|
189
|
-
method,
|
|
190
|
-
headers: headerRecord
|
|
191
|
-
};
|
|
192
|
-
if (!(method === "GET" || method === "HEAD")) {
|
|
193
|
-
init.body = import_node_stream.Readable.toWeb(incoming);
|
|
194
|
-
init.duplex = "half";
|
|
195
|
-
}
|
|
196
|
-
return new Request(url, init);
|
|
197
|
-
};
|
|
198
|
-
var getRequestCache = Symbol("getRequestCache");
|
|
199
|
-
var requestCache = Symbol("requestCache");
|
|
200
|
-
var incomingKey = Symbol("incomingKey");
|
|
201
|
-
var requestPrototype = {
|
|
202
|
-
get method() {
|
|
203
|
-
return this[incomingKey].method || "GET";
|
|
204
|
-
},
|
|
205
|
-
get url() {
|
|
206
|
-
return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
|
|
207
|
-
},
|
|
208
|
-
[getRequestCache]() {
|
|
209
|
-
return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
[
|
|
213
|
-
"body",
|
|
214
|
-
"bodyUsed",
|
|
215
|
-
"cache",
|
|
216
|
-
"credentials",
|
|
217
|
-
"destination",
|
|
218
|
-
"headers",
|
|
219
|
-
"integrity",
|
|
220
|
-
"mode",
|
|
221
|
-
"redirect",
|
|
222
|
-
"referrer",
|
|
223
|
-
"referrerPolicy",
|
|
224
|
-
"signal"
|
|
225
|
-
].forEach((k) => {
|
|
226
|
-
Object.defineProperty(requestPrototype, k, {
|
|
227
|
-
get() {
|
|
228
|
-
return this[getRequestCache]()[k];
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
233
|
-
Object.defineProperty(requestPrototype, k, {
|
|
234
|
-
value: function() {
|
|
235
|
-
return this[getRequestCache]()[k]();
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
Object.setPrototypeOf(requestPrototype, global.Request.prototype);
|
|
240
|
-
var newRequest = (incoming) => {
|
|
241
|
-
const req = Object.create(requestPrototype);
|
|
242
|
-
req[incomingKey] = incoming;
|
|
243
|
-
return req;
|
|
244
|
-
};
|
|
245
|
-
|
|
246
244
|
// src/listener.ts
|
|
247
245
|
var regBuffer = /^no$/i;
|
|
248
246
|
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
@@ -255,6 +253,9 @@ var handleResponseError = (e, outgoing) => {
|
|
|
255
253
|
console.info("The user aborted a request.");
|
|
256
254
|
} else {
|
|
257
255
|
console.error(e);
|
|
256
|
+
if (!outgoing.headersSent)
|
|
257
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
258
|
+
outgoing.end(`Error: ${err.message}`);
|
|
258
259
|
outgoing.destroy(err);
|
|
259
260
|
}
|
|
260
261
|
};
|
|
@@ -275,6 +276,13 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
275
276
|
if (res instanceof Promise) {
|
|
276
277
|
res = await res.catch(handleFetchError);
|
|
277
278
|
}
|
|
279
|
+
if (!(res instanceof Response)) {
|
|
280
|
+
return handleResponseError(
|
|
281
|
+
// @ts-expect-error the object must have `toString()`
|
|
282
|
+
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
283
|
+
outgoing
|
|
284
|
+
);
|
|
285
|
+
}
|
|
278
286
|
if (cacheKey in res) {
|
|
279
287
|
try {
|
|
280
288
|
return responseViaCache(res, outgoing);
|
package/dist/vercel.mjs
CHANGED
|
@@ -1,5 +1,68 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import
|
|
1
|
+
// src/request.ts
|
|
2
|
+
import { Readable } from "stream";
|
|
3
|
+
var newRequestFromIncoming = (method, url, incoming) => {
|
|
4
|
+
const headerRecord = [];
|
|
5
|
+
const len = incoming.rawHeaders.length;
|
|
6
|
+
for (let i = 0; i < len; i += 2) {
|
|
7
|
+
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
8
|
+
}
|
|
9
|
+
const init = {
|
|
10
|
+
method,
|
|
11
|
+
headers: headerRecord
|
|
12
|
+
};
|
|
13
|
+
if (!(method === "GET" || method === "HEAD")) {
|
|
14
|
+
init.body = Readable.toWeb(incoming);
|
|
15
|
+
init.duplex = "half";
|
|
16
|
+
}
|
|
17
|
+
return new Request(url, init);
|
|
18
|
+
};
|
|
19
|
+
var getRequestCache = Symbol("getRequestCache");
|
|
20
|
+
var requestCache = Symbol("requestCache");
|
|
21
|
+
var incomingKey = Symbol("incomingKey");
|
|
22
|
+
var requestPrototype = {
|
|
23
|
+
get method() {
|
|
24
|
+
return this[incomingKey].method || "GET";
|
|
25
|
+
},
|
|
26
|
+
get url() {
|
|
27
|
+
return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
|
|
28
|
+
},
|
|
29
|
+
[getRequestCache]() {
|
|
30
|
+
return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
[
|
|
34
|
+
"body",
|
|
35
|
+
"bodyUsed",
|
|
36
|
+
"cache",
|
|
37
|
+
"credentials",
|
|
38
|
+
"destination",
|
|
39
|
+
"headers",
|
|
40
|
+
"integrity",
|
|
41
|
+
"mode",
|
|
42
|
+
"redirect",
|
|
43
|
+
"referrer",
|
|
44
|
+
"referrerPolicy",
|
|
45
|
+
"signal"
|
|
46
|
+
].forEach((k) => {
|
|
47
|
+
Object.defineProperty(requestPrototype, k, {
|
|
48
|
+
get() {
|
|
49
|
+
return this[getRequestCache]()[k];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
54
|
+
Object.defineProperty(requestPrototype, k, {
|
|
55
|
+
value: function() {
|
|
56
|
+
return this[getRequestCache]()[k]();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
Object.setPrototypeOf(requestPrototype, global.Request.prototype);
|
|
61
|
+
var newRequest = (incoming) => {
|
|
62
|
+
const req = Object.create(requestPrototype);
|
|
63
|
+
req[incomingKey] = incoming;
|
|
64
|
+
return req;
|
|
65
|
+
};
|
|
3
66
|
|
|
4
67
|
// src/utils.ts
|
|
5
68
|
function writeFromReadableStream(stream, writable) {
|
|
@@ -124,6 +187,7 @@ Object.defineProperty(global, "Response", {
|
|
|
124
187
|
});
|
|
125
188
|
|
|
126
189
|
// src/globals.ts
|
|
190
|
+
import crypto from "crypto";
|
|
127
191
|
Object.defineProperty(global, "Response", {
|
|
128
192
|
value: Response2
|
|
129
193
|
});
|
|
@@ -141,72 +205,6 @@ global.fetch = (info, init) => {
|
|
|
141
205
|
return webFetch(info, init);
|
|
142
206
|
};
|
|
143
207
|
|
|
144
|
-
// src/request.ts
|
|
145
|
-
import { Readable } from "stream";
|
|
146
|
-
var newRequestFromIncoming = (method, url, incoming) => {
|
|
147
|
-
const headerRecord = [];
|
|
148
|
-
const len = incoming.rawHeaders.length;
|
|
149
|
-
for (let i = 0; i < len; i += 2) {
|
|
150
|
-
headerRecord.push([incoming.rawHeaders[i], incoming.rawHeaders[i + 1]]);
|
|
151
|
-
}
|
|
152
|
-
const init = {
|
|
153
|
-
method,
|
|
154
|
-
headers: headerRecord
|
|
155
|
-
};
|
|
156
|
-
if (!(method === "GET" || method === "HEAD")) {
|
|
157
|
-
init.body = Readable.toWeb(incoming);
|
|
158
|
-
init.duplex = "half";
|
|
159
|
-
}
|
|
160
|
-
return new Request(url, init);
|
|
161
|
-
};
|
|
162
|
-
var getRequestCache = Symbol("getRequestCache");
|
|
163
|
-
var requestCache = Symbol("requestCache");
|
|
164
|
-
var incomingKey = Symbol("incomingKey");
|
|
165
|
-
var requestPrototype = {
|
|
166
|
-
get method() {
|
|
167
|
-
return this[incomingKey].method || "GET";
|
|
168
|
-
},
|
|
169
|
-
get url() {
|
|
170
|
-
return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
|
|
171
|
-
},
|
|
172
|
-
[getRequestCache]() {
|
|
173
|
-
return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
|
|
174
|
-
}
|
|
175
|
-
};
|
|
176
|
-
[
|
|
177
|
-
"body",
|
|
178
|
-
"bodyUsed",
|
|
179
|
-
"cache",
|
|
180
|
-
"credentials",
|
|
181
|
-
"destination",
|
|
182
|
-
"headers",
|
|
183
|
-
"integrity",
|
|
184
|
-
"mode",
|
|
185
|
-
"redirect",
|
|
186
|
-
"referrer",
|
|
187
|
-
"referrerPolicy",
|
|
188
|
-
"signal"
|
|
189
|
-
].forEach((k) => {
|
|
190
|
-
Object.defineProperty(requestPrototype, k, {
|
|
191
|
-
get() {
|
|
192
|
-
return this[getRequestCache]()[k];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
["arrayBuffer", "blob", "clone", "formData", "json", "text"].forEach((k) => {
|
|
197
|
-
Object.defineProperty(requestPrototype, k, {
|
|
198
|
-
value: function() {
|
|
199
|
-
return this[getRequestCache]()[k]();
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
Object.setPrototypeOf(requestPrototype, global.Request.prototype);
|
|
204
|
-
var newRequest = (incoming) => {
|
|
205
|
-
const req = Object.create(requestPrototype);
|
|
206
|
-
req[incomingKey] = incoming;
|
|
207
|
-
return req;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
208
|
// src/listener.ts
|
|
211
209
|
var regBuffer = /^no$/i;
|
|
212
210
|
var regContentType = /^(application\/json\b|text\/(?!event-stream\b))/i;
|
|
@@ -219,6 +217,9 @@ var handleResponseError = (e, outgoing) => {
|
|
|
219
217
|
console.info("The user aborted a request.");
|
|
220
218
|
} else {
|
|
221
219
|
console.error(e);
|
|
220
|
+
if (!outgoing.headersSent)
|
|
221
|
+
outgoing.writeHead(500, { "Content-Type": "text/plain" });
|
|
222
|
+
outgoing.end(`Error: ${err.message}`);
|
|
222
223
|
outgoing.destroy(err);
|
|
223
224
|
}
|
|
224
225
|
};
|
|
@@ -239,6 +240,13 @@ var responseViaResponseObject = async (res, outgoing) => {
|
|
|
239
240
|
if (res instanceof Promise) {
|
|
240
241
|
res = await res.catch(handleFetchError);
|
|
241
242
|
}
|
|
243
|
+
if (!(res instanceof Response)) {
|
|
244
|
+
return handleResponseError(
|
|
245
|
+
// @ts-expect-error the object must have `toString()`
|
|
246
|
+
new Error(`The response is not an instance of Response, but ${res.toString()}`),
|
|
247
|
+
outgoing
|
|
248
|
+
);
|
|
249
|
+
}
|
|
242
250
|
if (cacheKey in res) {
|
|
243
251
|
try {
|
|
244
252
|
return responseViaCache(res, outgoing);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono/node-server",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.4",
|
|
4
4
|
"description": "Node.js Adapter for Hono",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -43,7 +43,9 @@
|
|
|
43
43
|
"watch": "tsup --watch",
|
|
44
44
|
"postbuild": "publint",
|
|
45
45
|
"prerelease": "yarn build && yarn test",
|
|
46
|
-
"release": "np"
|
|
46
|
+
"release": "np",
|
|
47
|
+
"lint": "eslint --ext js,ts src test",
|
|
48
|
+
"lint:fix": "eslint --ext js,ts src test --fix"
|
|
47
49
|
},
|
|
48
50
|
"license": "MIT",
|
|
49
51
|
"repository": {
|
|
@@ -60,10 +62,12 @@
|
|
|
60
62
|
"node": ">=18.14.1"
|
|
61
63
|
},
|
|
62
64
|
"devDependencies": {
|
|
65
|
+
"@hono/eslint-config": "^0.0.2",
|
|
63
66
|
"@types/jest": "^29.5.3",
|
|
64
67
|
"@types/node": "^20.10.0",
|
|
65
68
|
"@types/supertest": "^2.0.12",
|
|
66
|
-
"
|
|
69
|
+
"eslint": "^8.55.0",
|
|
70
|
+
"hono": "^3.11.7",
|
|
67
71
|
"jest": "^29.6.1",
|
|
68
72
|
"np": "^7.7.0",
|
|
69
73
|
"publint": "^0.1.16",
|