@hono/node-server 1.19.5 → 1.19.7

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.
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
package/dist/globals.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
 
2
- export { }
2
+ export { }
@@ -22,4 +22,4 @@ declare const abortControllerKey: unique symbol;
22
22
  declare const getAbortController: unique symbol;
23
23
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
24
24
 
25
- export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
25
+ export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
package/dist/request.d.ts CHANGED
@@ -22,4 +22,4 @@ declare const abortControllerKey: unique symbol;
22
22
  declare const getAbortController: unique symbol;
23
23
  declare const newRequest: (incoming: IncomingMessage | Http2ServerRequest, defaultHostname?: string) => any;
24
24
 
25
- export { GlobalRequest, IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
25
+ export { GlobalRequest, type IncomingMessageWithWrapBodyStream, Request, RequestError, abortControllerKey, getAbortController, newRequest, toRequestError, wrapBodyStream };
@@ -23,4 +23,4 @@ declare class Response {
23
23
  get ok(): boolean;
24
24
  }
25
25
 
26
- export { GlobalResponse, InternalCache, Response, cacheKey };
26
+ export { GlobalResponse, type InternalCache, Response, cacheKey };
@@ -23,4 +23,4 @@ declare class Response {
23
23
  get ok(): boolean;
24
24
  }
25
25
 
26
- export { GlobalResponse, InternalCache, Response, cacheKey };
26
+ export { GlobalResponse, type InternalCache, Response, cacheKey };
@@ -14,4 +14,4 @@ type ServeStaticOptions<E extends Env = Env> = {
14
14
  };
15
15
  declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
16
16
 
17
- export { ServeStaticOptions, serveStatic };
17
+ export { type ServeStaticOptions, serveStatic };
@@ -14,4 +14,4 @@ type ServeStaticOptions<E extends Env = Env> = {
14
14
  };
15
15
  declare const serveStatic: <E extends Env = any>(options?: ServeStaticOptions<E>) => MiddlewareHandler<E>;
16
16
 
17
- export { ServeStaticOptions, serveStatic };
17
+ export { type ServeStaticOptions, serveStatic };
@@ -55,7 +55,7 @@ var createStreamBody = (stream) => {
55
55
  var getStats = (path) => {
56
56
  let stats;
57
57
  try {
58
- stats = (0, import_node_fs.lstatSync)(path);
58
+ stats = (0, import_node_fs.statSync)(path);
59
59
  } catch {
60
60
  }
61
61
  return stats;
@@ -98,7 +98,6 @@ var serveStatic = (options = { root: "" }) => {
98
98
  await options.onNotFound?.(path, c);
99
99
  return next();
100
100
  }
101
- await options.onFound?.(path, c);
102
101
  const mimeType = (0, import_mime.getMimeType)(path);
103
102
  c.header("Content-Type", mimeType || "application/octet-stream");
104
103
  if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
@@ -119,30 +118,33 @@ var serveStatic = (options = { root: "" }) => {
119
118
  }
120
119
  }
121
120
  }
121
+ let result;
122
122
  const size = stats.size;
123
+ const range = c.req.header("range") || "";
123
124
  if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
124
125
  c.header("Content-Length", size.toString());
125
126
  c.status(200);
126
- return c.body(null);
127
- }
128
- const range = c.req.header("range") || "";
129
- if (!range) {
127
+ result = c.body(null);
128
+ } else if (!range) {
130
129
  c.header("Content-Length", size.toString());
131
- return c.body(createStreamBody((0, import_node_fs.createReadStream)(path)), 200);
132
- }
133
- c.header("Accept-Ranges", "bytes");
134
- c.header("Date", stats.birthtime.toUTCString());
135
- const parts = range.replace(/bytes=/, "").split("-", 2);
136
- const start = parseInt(parts[0], 10) || 0;
137
- let end = parseInt(parts[1], 10) || size - 1;
138
- if (size < end - start + 1) {
139
- end = size - 1;
130
+ result = c.body(createStreamBody((0, import_node_fs.createReadStream)(path)), 200);
131
+ } else {
132
+ c.header("Accept-Ranges", "bytes");
133
+ c.header("Date", stats.birthtime.toUTCString());
134
+ const parts = range.replace(/bytes=/, "").split("-", 2);
135
+ const start = parseInt(parts[0], 10) || 0;
136
+ let end = parseInt(parts[1], 10) || size - 1;
137
+ if (size < end - start + 1) {
138
+ end = size - 1;
139
+ }
140
+ const chunksize = end - start + 1;
141
+ const stream = (0, import_node_fs.createReadStream)(path, { start, end });
142
+ c.header("Content-Length", chunksize.toString());
143
+ c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
144
+ result = c.body(createStreamBody(stream), 206);
140
145
  }
141
- const chunksize = end - start + 1;
142
- const stream = (0, import_node_fs.createReadStream)(path, { start, end });
143
- c.header("Content-Length", chunksize.toString());
144
- c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
145
- return c.body(createStreamBody(stream), 206);
146
+ await options.onFound?.(path, c);
147
+ return result;
146
148
  };
147
149
  };
148
150
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,6 +1,6 @@
1
1
  // src/serve-static.ts
2
2
  import { getMimeType } from "hono/utils/mime";
3
- import { createReadStream, lstatSync, existsSync } from "fs";
3
+ import { createReadStream, statSync, existsSync } from "fs";
4
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 = {
@@ -31,7 +31,7 @@ var createStreamBody = (stream) => {
31
31
  var getStats = (path) => {
32
32
  let stats;
33
33
  try {
34
- stats = lstatSync(path);
34
+ stats = statSync(path);
35
35
  } catch {
36
36
  }
37
37
  return stats;
@@ -74,7 +74,6 @@ var serveStatic = (options = { root: "" }) => {
74
74
  await options.onNotFound?.(path, c);
75
75
  return next();
76
76
  }
77
- await options.onFound?.(path, c);
78
77
  const mimeType = getMimeType(path);
79
78
  c.header("Content-Type", mimeType || "application/octet-stream");
80
79
  if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
@@ -95,30 +94,33 @@ var serveStatic = (options = { root: "" }) => {
95
94
  }
96
95
  }
97
96
  }
97
+ let result;
98
98
  const size = stats.size;
99
+ const range = c.req.header("range") || "";
99
100
  if (c.req.method == "HEAD" || c.req.method == "OPTIONS") {
100
101
  c.header("Content-Length", size.toString());
101
102
  c.status(200);
102
- return c.body(null);
103
- }
104
- const range = c.req.header("range") || "";
105
- if (!range) {
103
+ result = c.body(null);
104
+ } else if (!range) {
106
105
  c.header("Content-Length", size.toString());
107
- return c.body(createStreamBody(createReadStream(path)), 200);
108
- }
109
- c.header("Accept-Ranges", "bytes");
110
- c.header("Date", stats.birthtime.toUTCString());
111
- const parts = range.replace(/bytes=/, "").split("-", 2);
112
- const start = parseInt(parts[0], 10) || 0;
113
- let end = parseInt(parts[1], 10) || size - 1;
114
- if (size < end - start + 1) {
115
- end = size - 1;
106
+ result = c.body(createStreamBody(createReadStream(path)), 200);
107
+ } else {
108
+ c.header("Accept-Ranges", "bytes");
109
+ c.header("Date", stats.birthtime.toUTCString());
110
+ const parts = range.replace(/bytes=/, "").split("-", 2);
111
+ const start = parseInt(parts[0], 10) || 0;
112
+ let end = parseInt(parts[1], 10) || size - 1;
113
+ if (size < end - start + 1) {
114
+ end = size - 1;
115
+ }
116
+ const chunksize = end - start + 1;
117
+ const stream = createReadStream(path, { start, end });
118
+ c.header("Content-Length", chunksize.toString());
119
+ c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
120
+ result = c.body(createStreamBody(stream), 206);
116
121
  }
117
- const chunksize = end - start + 1;
118
- const stream = createReadStream(path, { start, end });
119
- c.header("Content-Length", chunksize.toString());
120
- c.header("Content-Range", `bytes ${start}-${end}/${stats.size}`);
121
- return c.body(createStreamBody(stream), 206);
122
+ await options.onFound?.(path, c);
123
+ return result;
122
124
  };
123
125
  };
124
126
  export {
package/dist/types.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
- import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
1
+ import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
2
+ import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
3
3
  import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
4
4
 
5
5
  type HttpBindings = {
@@ -41,4 +41,4 @@ type Options = {
41
41
  } & ServerOptions;
42
42
  type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
43
43
 
44
- export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
44
+ export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { IncomingMessage, ServerResponse, Server, ServerOptions as ServerOptions$1, createServer } from 'node:http';
2
- import { Http2ServerRequest, Http2ServerResponse, Http2Server, Http2SecureServer, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer } from 'node:http2';
1
+ import { IncomingMessage, ServerResponse, ServerOptions as ServerOptions$1, createServer, Server } from 'node:http';
2
+ import { Http2ServerRequest, Http2ServerResponse, ServerOptions as ServerOptions$3, createServer as createServer$2, SecureServerOptions, createSecureServer, Http2Server, Http2SecureServer } from 'node:http2';
3
3
  import { ServerOptions as ServerOptions$2, createServer as createServer$1 } from 'node:https';
4
4
 
5
5
  type HttpBindings = {
@@ -41,4 +41,4 @@ type Options = {
41
41
  } & ServerOptions;
42
42
  type CustomErrorHandler = (err: unknown) => void | Response | Promise<void | Response>;
43
43
 
44
- export { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
44
+ export type { CustomErrorHandler, FetchCallback, Http2Bindings, HttpBindings, NextHandlerOption, Options, ServerOptions, ServerType };
package/dist/utils.d.mts CHANGED
@@ -2,8 +2,8 @@ import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
4
  declare function readWithoutBlocking(readPromise: Promise<ReadableStreamReadResult<Uint8Array>>): Promise<ReadableStreamReadResult<Uint8Array> | undefined>;
5
- declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<void>;
6
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
5
+ declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<undefined>;
6
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
7
7
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
8
8
 
9
9
  export { buildOutgoingHttpHeaders, readWithoutBlocking, writeFromReadableStream, writeFromReadableStreamDefaultReader };
package/dist/utils.d.ts CHANGED
@@ -2,8 +2,8 @@ import { OutgoingHttpHeaders } from 'node:http';
2
2
  import { Writable } from 'node:stream';
3
3
 
4
4
  declare function readWithoutBlocking(readPromise: Promise<ReadableStreamReadResult<Uint8Array>>): Promise<ReadableStreamReadResult<Uint8Array> | undefined>;
5
- declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<void>;
6
- declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<void> | undefined;
5
+ declare function writeFromReadableStreamDefaultReader(reader: ReadableStreamDefaultReader<Uint8Array>, writable: Writable, currentReadPromise?: Promise<ReadableStreamReadResult<Uint8Array>> | undefined): Promise<undefined>;
6
+ declare function writeFromReadableStream(stream: ReadableStream<Uint8Array>, writable: Writable): Promise<undefined> | undefined;
7
7
  declare const buildOutgoingHttpHeaders: (headers: Headers | HeadersInit | null | undefined) => OutgoingHttpHeaders;
8
8
 
9
9
  export { buildOutgoingHttpHeaders, readWithoutBlocking, writeFromReadableStream, writeFromReadableStreamDefaultReader };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.19.5",
3
+ "version": "1.19.7",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",