@hono/node-server 1.16.0 → 1.17.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/README.md CHANGED
@@ -128,6 +128,7 @@ serve({
128
128
  ### `autoCleanupIncoming`
129
129
 
130
130
  The default value is `true`. The Node.js Adapter automatically cleans up (explicitly call `destroy()` method) if application is not finished to consume the incoming request. If you don't want to do that, set `false`.
131
+
131
132
  If the application accepts connections from arbitrary clients, this cleanup must be done otherwise incomplete requests from clients may cause the application to stop responding. If your application only accepts connections from trusted clients, such as in a reverse proxy environment and there is no process that returns a response without reading the body of the POST request all the way through, you can improve performance by setting it to `false`.
132
133
 
133
134
  ```ts
@@ -167,7 +168,7 @@ import { serveStatic } from '@hono/node-server/serve-static'
167
168
  app.use('/static/*', serveStatic({ root: './' }))
168
169
  ```
169
170
 
170
- Note that `root` must be _relative_ to the current working directory from which the app was started. Absolute paths are not supported.
171
+ If using a relative path, `root` will be relative to the current working directory from which the app was started.
171
172
 
172
173
  This can cause confusion when running your application locally.
173
174
 
package/dist/index.js CHANGED
@@ -295,26 +295,23 @@ function writeFromReadableStream(stream, writable) {
295
295
  if (stream.locked) {
296
296
  throw new TypeError("ReadableStream is locked.");
297
297
  } else if (writable.destroyed) {
298
- stream.cancel();
299
298
  return;
300
299
  }
301
300
  const reader = stream.getReader();
302
- writable.on("close", cancel);
303
- writable.on("error", cancel);
304
- reader.read().then(flow, cancel);
301
+ const handleError = () => {
302
+ };
303
+ writable.on("error", handleError);
304
+ reader.read().then(flow, handleStreamError);
305
305
  return reader.closed.finally(() => {
306
- writable.off("close", cancel);
307
- writable.off("error", cancel);
306
+ writable.off("error", handleError);
308
307
  });
309
- function cancel(error) {
310
- reader.cancel(error).catch(() => {
311
- });
308
+ function handleStreamError(error) {
312
309
  if (error) {
313
310
  writable.destroy(error);
314
311
  }
315
312
  }
316
313
  function onDrain() {
317
- reader.read().then(flow, cancel);
314
+ reader.read().then(flow, handleStreamError);
318
315
  }
319
316
  function flow({ done, value }) {
320
317
  try {
@@ -323,10 +320,10 @@ function writeFromReadableStream(stream, writable) {
323
320
  } else if (!writable.write(value)) {
324
321
  writable.once("drain", onDrain);
325
322
  } else {
326
- return reader.read().then(flow, cancel);
323
+ return reader.read().then(flow, handleStreamError);
327
324
  }
328
325
  } catch (e) {
329
- cancel(e);
326
+ handleStreamError(e);
330
327
  }
331
328
  }
332
329
  }
package/dist/index.mjs CHANGED
@@ -256,26 +256,23 @@ function writeFromReadableStream(stream, writable) {
256
256
  if (stream.locked) {
257
257
  throw new TypeError("ReadableStream is locked.");
258
258
  } else if (writable.destroyed) {
259
- stream.cancel();
260
259
  return;
261
260
  }
262
261
  const reader = stream.getReader();
263
- writable.on("close", cancel);
264
- writable.on("error", cancel);
265
- reader.read().then(flow, cancel);
262
+ const handleError = () => {
263
+ };
264
+ writable.on("error", handleError);
265
+ reader.read().then(flow, handleStreamError);
266
266
  return reader.closed.finally(() => {
267
- writable.off("close", cancel);
268
- writable.off("error", cancel);
267
+ writable.off("error", handleError);
269
268
  });
270
- function cancel(error) {
271
- reader.cancel(error).catch(() => {
272
- });
269
+ function handleStreamError(error) {
273
270
  if (error) {
274
271
  writable.destroy(error);
275
272
  }
276
273
  }
277
274
  function onDrain() {
278
- reader.read().then(flow, cancel);
275
+ reader.read().then(flow, handleStreamError);
279
276
  }
280
277
  function flow({ done, value }) {
281
278
  try {
@@ -284,10 +281,10 @@ function writeFromReadableStream(stream, writable) {
284
281
  } else if (!writable.write(value)) {
285
282
  writable.once("drain", onDrain);
286
283
  } else {
287
- return reader.read().then(flow, cancel);
284
+ return reader.read().then(flow, handleStreamError);
288
285
  }
289
286
  } catch (e) {
290
- cancel(e);
287
+ handleStreamError(e);
291
288
  }
292
289
  }
293
290
  }
package/dist/listener.js CHANGED
@@ -287,26 +287,23 @@ function writeFromReadableStream(stream, writable) {
287
287
  if (stream.locked) {
288
288
  throw new TypeError("ReadableStream is locked.");
289
289
  } else if (writable.destroyed) {
290
- stream.cancel();
291
290
  return;
292
291
  }
293
292
  const reader = stream.getReader();
294
- writable.on("close", cancel);
295
- writable.on("error", cancel);
296
- reader.read().then(flow, cancel);
293
+ const handleError = () => {
294
+ };
295
+ writable.on("error", handleError);
296
+ reader.read().then(flow, handleStreamError);
297
297
  return reader.closed.finally(() => {
298
- writable.off("close", cancel);
299
- writable.off("error", cancel);
298
+ writable.off("error", handleError);
300
299
  });
301
- function cancel(error) {
302
- reader.cancel(error).catch(() => {
303
- });
300
+ function handleStreamError(error) {
304
301
  if (error) {
305
302
  writable.destroy(error);
306
303
  }
307
304
  }
308
305
  function onDrain() {
309
- reader.read().then(flow, cancel);
306
+ reader.read().then(flow, handleStreamError);
310
307
  }
311
308
  function flow({ done, value }) {
312
309
  try {
@@ -315,10 +312,10 @@ function writeFromReadableStream(stream, writable) {
315
312
  } else if (!writable.write(value)) {
316
313
  writable.once("drain", onDrain);
317
314
  } else {
318
- return reader.read().then(flow, cancel);
315
+ return reader.read().then(flow, handleStreamError);
319
316
  }
320
317
  } catch (e) {
321
- cancel(e);
318
+ handleStreamError(e);
322
319
  }
323
320
  }
324
321
  }
package/dist/listener.mjs CHANGED
@@ -253,26 +253,23 @@ function writeFromReadableStream(stream, writable) {
253
253
  if (stream.locked) {
254
254
  throw new TypeError("ReadableStream is locked.");
255
255
  } else if (writable.destroyed) {
256
- stream.cancel();
257
256
  return;
258
257
  }
259
258
  const reader = stream.getReader();
260
- writable.on("close", cancel);
261
- writable.on("error", cancel);
262
- reader.read().then(flow, cancel);
259
+ const handleError = () => {
260
+ };
261
+ writable.on("error", handleError);
262
+ reader.read().then(flow, handleStreamError);
263
263
  return reader.closed.finally(() => {
264
- writable.off("close", cancel);
265
- writable.off("error", cancel);
264
+ writable.off("error", handleError);
266
265
  });
267
- function cancel(error) {
268
- reader.cancel(error).catch(() => {
269
- });
266
+ function handleStreamError(error) {
270
267
  if (error) {
271
268
  writable.destroy(error);
272
269
  }
273
270
  }
274
271
  function onDrain() {
275
- reader.read().then(flow, cancel);
272
+ reader.read().then(flow, handleStreamError);
276
273
  }
277
274
  function flow({ done, value }) {
278
275
  try {
@@ -281,10 +278,10 @@ function writeFromReadableStream(stream, writable) {
281
278
  } else if (!writable.write(value)) {
282
279
  writable.once("drain", onDrain);
283
280
  } else {
284
- return reader.read().then(flow, cancel);
281
+ return reader.read().then(flow, handleStreamError);
285
282
  }
286
283
  } catch (e) {
287
- cancel(e);
284
+ handleStreamError(e);
288
285
  }
289
286
  }
290
287
  }
@@ -23,9 +23,9 @@ __export(serve_static_exports, {
23
23
  serveStatic: () => serveStatic
24
24
  });
25
25
  module.exports = __toCommonJS(serve_static_exports);
26
- var import_filepath = require("hono/utils/filepath");
27
26
  var import_mime = require("hono/utils/mime");
28
27
  var import_node_fs = require("fs");
28
+ var import_node_path = require("path");
29
29
  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;
30
30
  var ENCODINGS = {
31
31
  br: ".br",
@@ -49,9 +49,6 @@ var createStreamBody = (stream) => {
49
49
  });
50
50
  return body;
51
51
  };
52
- var addCurrentDirPrefix = (path) => {
53
- return `./${path}`;
54
- };
55
52
  var getStats = (path) => {
56
53
  let stats;
57
54
  try {
@@ -61,38 +58,34 @@ var getStats = (path) => {
61
58
  return stats;
62
59
  };
63
60
  var serveStatic = (options = { root: "" }) => {
61
+ const root = options.root || "";
62
+ const optionPath = options.path;
64
63
  return async (c, next) => {
65
64
  if (c.finalized) {
66
65
  return next();
67
66
  }
68
67
  let filename;
69
- try {
70
- filename = options.path ?? decodeURIComponent(c.req.path);
71
- } catch {
72
- await options.onNotFound?.(c.req.path, c);
73
- return next();
74
- }
75
- let path = (0, import_filepath.getFilePathWithoutDefaultDocument)({
76
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename,
77
- root: options.root
78
- });
79
- if (path) {
80
- path = addCurrentDirPrefix(path);
68
+ if (optionPath) {
69
+ filename = optionPath;
81
70
  } else {
82
- return next();
71
+ try {
72
+ filename = decodeURIComponent(c.req.path);
73
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
74
+ throw new Error();
75
+ }
76
+ } catch {
77
+ await options.onNotFound?.(c.req.path, c);
78
+ return next();
79
+ }
83
80
  }
81
+ let path = (0, import_node_path.join)(
82
+ root,
83
+ !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
84
+ );
84
85
  let stats = getStats(path);
85
86
  if (stats && stats.isDirectory()) {
86
- path = (0, import_filepath.getFilePath)({
87
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename,
88
- root: options.root,
89
- defaultDocument: options.index ?? "index.html"
90
- });
91
- if (path) {
92
- path = addCurrentDirPrefix(path);
93
- } else {
94
- return next();
95
- }
87
+ const indexFile = options.index ?? "index.html";
88
+ path = (0, import_node_path.join)(path, indexFile);
96
89
  stats = getStats(path);
97
90
  }
98
91
  if (!stats) {
@@ -1,7 +1,7 @@
1
1
  // src/serve-static.ts
2
- import { getFilePath, getFilePathWithoutDefaultDocument } from "hono/utils/filepath";
3
2
  import { getMimeType } from "hono/utils/mime";
4
3
  import { createReadStream, lstatSync } from "fs";
4
+ import { join } from "path";
5
5
  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;
6
6
  var ENCODINGS = {
7
7
  br: ".br",
@@ -25,9 +25,6 @@ var createStreamBody = (stream) => {
25
25
  });
26
26
  return body;
27
27
  };
28
- var addCurrentDirPrefix = (path) => {
29
- return `./${path}`;
30
- };
31
28
  var getStats = (path) => {
32
29
  let stats;
33
30
  try {
@@ -37,38 +34,34 @@ var getStats = (path) => {
37
34
  return stats;
38
35
  };
39
36
  var serveStatic = (options = { root: "" }) => {
37
+ const root = options.root || "";
38
+ const optionPath = options.path;
40
39
  return async (c, next) => {
41
40
  if (c.finalized) {
42
41
  return next();
43
42
  }
44
43
  let filename;
45
- try {
46
- filename = options.path ?? decodeURIComponent(c.req.path);
47
- } catch {
48
- await options.onNotFound?.(c.req.path, c);
49
- return next();
50
- }
51
- let path = getFilePathWithoutDefaultDocument({
52
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename,
53
- root: options.root
54
- });
55
- if (path) {
56
- path = addCurrentDirPrefix(path);
44
+ if (optionPath) {
45
+ filename = optionPath;
57
46
  } else {
58
- return next();
47
+ try {
48
+ filename = decodeURIComponent(c.req.path);
49
+ if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
50
+ throw new Error();
51
+ }
52
+ } catch {
53
+ await options.onNotFound?.(c.req.path, c);
54
+ return next();
55
+ }
59
56
  }
57
+ let path = join(
58
+ root,
59
+ !optionPath && options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename
60
+ );
60
61
  let stats = getStats(path);
61
62
  if (stats && stats.isDirectory()) {
62
- path = getFilePath({
63
- filename: options.rewriteRequestPath ? options.rewriteRequestPath(filename, c) : filename,
64
- root: options.root,
65
- defaultDocument: options.index ?? "index.html"
66
- });
67
- if (path) {
68
- path = addCurrentDirPrefix(path);
69
- } else {
70
- return next();
71
- }
63
+ const indexFile = options.index ?? "index.html";
64
+ path = join(path, indexFile);
72
65
  stats = getStats(path);
73
66
  }
74
67
  if (!stats) {
package/dist/server.js CHANGED
@@ -291,26 +291,23 @@ function writeFromReadableStream(stream, writable) {
291
291
  if (stream.locked) {
292
292
  throw new TypeError("ReadableStream is locked.");
293
293
  } else if (writable.destroyed) {
294
- stream.cancel();
295
294
  return;
296
295
  }
297
296
  const reader = stream.getReader();
298
- writable.on("close", cancel);
299
- writable.on("error", cancel);
300
- reader.read().then(flow, cancel);
297
+ const handleError = () => {
298
+ };
299
+ writable.on("error", handleError);
300
+ reader.read().then(flow, handleStreamError);
301
301
  return reader.closed.finally(() => {
302
- writable.off("close", cancel);
303
- writable.off("error", cancel);
302
+ writable.off("error", handleError);
304
303
  });
305
- function cancel(error) {
306
- reader.cancel(error).catch(() => {
307
- });
304
+ function handleStreamError(error) {
308
305
  if (error) {
309
306
  writable.destroy(error);
310
307
  }
311
308
  }
312
309
  function onDrain() {
313
- reader.read().then(flow, cancel);
310
+ reader.read().then(flow, handleStreamError);
314
311
  }
315
312
  function flow({ done, value }) {
316
313
  try {
@@ -319,10 +316,10 @@ function writeFromReadableStream(stream, writable) {
319
316
  } else if (!writable.write(value)) {
320
317
  writable.once("drain", onDrain);
321
318
  } else {
322
- return reader.read().then(flow, cancel);
319
+ return reader.read().then(flow, handleStreamError);
323
320
  }
324
321
  } catch (e) {
325
- cancel(e);
322
+ handleStreamError(e);
326
323
  }
327
324
  }
328
325
  }
package/dist/server.mjs CHANGED
@@ -256,26 +256,23 @@ function writeFromReadableStream(stream, writable) {
256
256
  if (stream.locked) {
257
257
  throw new TypeError("ReadableStream is locked.");
258
258
  } else if (writable.destroyed) {
259
- stream.cancel();
260
259
  return;
261
260
  }
262
261
  const reader = stream.getReader();
263
- writable.on("close", cancel);
264
- writable.on("error", cancel);
265
- reader.read().then(flow, cancel);
262
+ const handleError = () => {
263
+ };
264
+ writable.on("error", handleError);
265
+ reader.read().then(flow, handleStreamError);
266
266
  return reader.closed.finally(() => {
267
- writable.off("close", cancel);
268
- writable.off("error", cancel);
267
+ writable.off("error", handleError);
269
268
  });
270
- function cancel(error) {
271
- reader.cancel(error).catch(() => {
272
- });
269
+ function handleStreamError(error) {
273
270
  if (error) {
274
271
  writable.destroy(error);
275
272
  }
276
273
  }
277
274
  function onDrain() {
278
- reader.read().then(flow, cancel);
275
+ reader.read().then(flow, handleStreamError);
279
276
  }
280
277
  function flow({ done, value }) {
281
278
  try {
@@ -284,10 +281,10 @@ function writeFromReadableStream(stream, writable) {
284
281
  } else if (!writable.write(value)) {
285
282
  writable.once("drain", onDrain);
286
283
  } else {
287
- return reader.read().then(flow, cancel);
284
+ return reader.read().then(flow, handleStreamError);
288
285
  }
289
286
  } catch (e) {
290
- cancel(e);
287
+ handleStreamError(e);
291
288
  }
292
289
  }
293
290
  }
package/dist/utils.js CHANGED
@@ -28,26 +28,23 @@ function writeFromReadableStream(stream, writable) {
28
28
  if (stream.locked) {
29
29
  throw new TypeError("ReadableStream is locked.");
30
30
  } else if (writable.destroyed) {
31
- stream.cancel();
32
31
  return;
33
32
  }
34
33
  const reader = stream.getReader();
35
- writable.on("close", cancel);
36
- writable.on("error", cancel);
37
- reader.read().then(flow, cancel);
34
+ const handleError = () => {
35
+ };
36
+ writable.on("error", handleError);
37
+ reader.read().then(flow, handleStreamError);
38
38
  return reader.closed.finally(() => {
39
- writable.off("close", cancel);
40
- writable.off("error", cancel);
39
+ writable.off("error", handleError);
41
40
  });
42
- function cancel(error) {
43
- reader.cancel(error).catch(() => {
44
- });
41
+ function handleStreamError(error) {
45
42
  if (error) {
46
43
  writable.destroy(error);
47
44
  }
48
45
  }
49
46
  function onDrain() {
50
- reader.read().then(flow, cancel);
47
+ reader.read().then(flow, handleStreamError);
51
48
  }
52
49
  function flow({ done, value }) {
53
50
  try {
@@ -56,10 +53,10 @@ function writeFromReadableStream(stream, writable) {
56
53
  } else if (!writable.write(value)) {
57
54
  writable.once("drain", onDrain);
58
55
  } else {
59
- return reader.read().then(flow, cancel);
56
+ return reader.read().then(flow, handleStreamError);
60
57
  }
61
58
  } catch (e) {
62
- cancel(e);
59
+ handleStreamError(e);
63
60
  }
64
61
  }
65
62
  }
package/dist/utils.mjs CHANGED
@@ -3,26 +3,23 @@ function writeFromReadableStream(stream, writable) {
3
3
  if (stream.locked) {
4
4
  throw new TypeError("ReadableStream is locked.");
5
5
  } else if (writable.destroyed) {
6
- stream.cancel();
7
6
  return;
8
7
  }
9
8
  const reader = stream.getReader();
10
- writable.on("close", cancel);
11
- writable.on("error", cancel);
12
- reader.read().then(flow, cancel);
9
+ const handleError = () => {
10
+ };
11
+ writable.on("error", handleError);
12
+ reader.read().then(flow, handleStreamError);
13
13
  return reader.closed.finally(() => {
14
- writable.off("close", cancel);
15
- writable.off("error", cancel);
14
+ writable.off("error", handleError);
16
15
  });
17
- function cancel(error) {
18
- reader.cancel(error).catch(() => {
19
- });
16
+ function handleStreamError(error) {
20
17
  if (error) {
21
18
  writable.destroy(error);
22
19
  }
23
20
  }
24
21
  function onDrain() {
25
- reader.read().then(flow, cancel);
22
+ reader.read().then(flow, handleStreamError);
26
23
  }
27
24
  function flow({ done, value }) {
28
25
  try {
@@ -31,10 +28,10 @@ function writeFromReadableStream(stream, writable) {
31
28
  } else if (!writable.write(value)) {
32
29
  writable.once("drain", onDrain);
33
30
  } else {
34
- return reader.read().then(flow, cancel);
31
+ return reader.read().then(flow, handleStreamError);
35
32
  }
36
33
  } catch (e) {
37
- cancel(e);
34
+ handleStreamError(e);
38
35
  }
39
36
  }
40
37
  }
package/dist/vercel.js CHANGED
@@ -289,26 +289,23 @@ function writeFromReadableStream(stream, writable) {
289
289
  if (stream.locked) {
290
290
  throw new TypeError("ReadableStream is locked.");
291
291
  } else if (writable.destroyed) {
292
- stream.cancel();
293
292
  return;
294
293
  }
295
294
  const reader = stream.getReader();
296
- writable.on("close", cancel);
297
- writable.on("error", cancel);
298
- reader.read().then(flow, cancel);
295
+ const handleError = () => {
296
+ };
297
+ writable.on("error", handleError);
298
+ reader.read().then(flow, handleStreamError);
299
299
  return reader.closed.finally(() => {
300
- writable.off("close", cancel);
301
- writable.off("error", cancel);
300
+ writable.off("error", handleError);
302
301
  });
303
- function cancel(error) {
304
- reader.cancel(error).catch(() => {
305
- });
302
+ function handleStreamError(error) {
306
303
  if (error) {
307
304
  writable.destroy(error);
308
305
  }
309
306
  }
310
307
  function onDrain() {
311
- reader.read().then(flow, cancel);
308
+ reader.read().then(flow, handleStreamError);
312
309
  }
313
310
  function flow({ done, value }) {
314
311
  try {
@@ -317,10 +314,10 @@ function writeFromReadableStream(stream, writable) {
317
314
  } else if (!writable.write(value)) {
318
315
  writable.once("drain", onDrain);
319
316
  } else {
320
- return reader.read().then(flow, cancel);
317
+ return reader.read().then(flow, handleStreamError);
321
318
  }
322
319
  } catch (e) {
323
- cancel(e);
320
+ handleStreamError(e);
324
321
  }
325
322
  }
326
323
  }
package/dist/vercel.mjs CHANGED
@@ -253,26 +253,23 @@ function writeFromReadableStream(stream, writable) {
253
253
  if (stream.locked) {
254
254
  throw new TypeError("ReadableStream is locked.");
255
255
  } else if (writable.destroyed) {
256
- stream.cancel();
257
256
  return;
258
257
  }
259
258
  const reader = stream.getReader();
260
- writable.on("close", cancel);
261
- writable.on("error", cancel);
262
- reader.read().then(flow, cancel);
259
+ const handleError = () => {
260
+ };
261
+ writable.on("error", handleError);
262
+ reader.read().then(flow, handleStreamError);
263
263
  return reader.closed.finally(() => {
264
- writable.off("close", cancel);
265
- writable.off("error", cancel);
264
+ writable.off("error", handleError);
266
265
  });
267
- function cancel(error) {
268
- reader.cancel(error).catch(() => {
269
- });
266
+ function handleStreamError(error) {
270
267
  if (error) {
271
268
  writable.destroy(error);
272
269
  }
273
270
  }
274
271
  function onDrain() {
275
- reader.read().then(flow, cancel);
272
+ reader.read().then(flow, handleStreamError);
276
273
  }
277
274
  function flow({ done, value }) {
278
275
  try {
@@ -281,10 +278,10 @@ function writeFromReadableStream(stream, writable) {
281
278
  } else if (!writable.write(value)) {
282
279
  writable.once("drain", onDrain);
283
280
  } else {
284
- return reader.read().then(flow, cancel);
281
+ return reader.read().then(flow, handleStreamError);
285
282
  }
286
283
  } catch (e) {
287
- cancel(e);
284
+ handleStreamError(e);
288
285
  }
289
286
  }
290
287
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.16.0",
3
+ "version": "1.17.1",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -54,7 +54,7 @@
54
54
  }
55
55
  },
56
56
  "scripts": {
57
- "test": "node --expose-gc ./node_modules/.bin/jest",
57
+ "test": "node --expose-gc node_modules/jest/bin/jest.js",
58
58
  "build": "tsup --external hono",
59
59
  "watch": "tsup --watch",
60
60
  "postbuild": "publint",