@hono/node-server 1.3.5 → 1.4.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
@@ -162,6 +162,22 @@ app.use(
162
162
  )
163
163
  ```
164
164
 
165
+ #### `onNotFound`
166
+
167
+ The `onNotFound` is useful for debugging. You can write a handle for when a file is not found.
168
+
169
+ ```ts
170
+ app.use(
171
+ '/static/*',
172
+ serveStatic({
173
+ root: './non-existent-dir',
174
+ onNotFound: (path, c) => {
175
+ console.log(`${path} is not found, request to ${c.req.path}`)
176
+ },
177
+ })
178
+ )
179
+ ```
180
+
165
181
  ## Related projects
166
182
 
167
183
  - Hono - <https://hono.dev>
package/dist/index.js CHANGED
@@ -40,6 +40,7 @@ module.exports = __toCommonJS(src_exports);
40
40
  var import_node_http = require("http");
41
41
 
42
42
  // src/request.ts
43
+ var import_node_path = require("path");
43
44
  var import_node_stream = require("stream");
44
45
  var newRequestFromIncoming = (method, url, incoming) => {
45
46
  const headerRecord = [];
@@ -65,7 +66,13 @@ var requestPrototype = {
65
66
  return this[incomingKey].method || "GET";
66
67
  },
67
68
  get url() {
68
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
69
+ let path = this[incomingKey]["path"];
70
+ if (!path) {
71
+ const originalPath = this[incomingKey].url;
72
+ path = /\.\./.test(originalPath) ? (0, import_node_path.resolve)(originalPath) : originalPath;
73
+ this[incomingKey]["path"] = path;
74
+ }
75
+ return `http://${this[incomingKey].headers.host}${path}`;
69
76
  },
70
77
  [getRequestCache]() {
71
78
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/index.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  import { createServer as createServerHTTP } from "http";
3
3
 
4
4
  // src/request.ts
5
+ import { resolve } from "path";
5
6
  import { Readable } from "stream";
6
7
  var newRequestFromIncoming = (method, url, incoming) => {
7
8
  const headerRecord = [];
@@ -27,7 +28,13 @@ var requestPrototype = {
27
28
  return this[incomingKey].method || "GET";
28
29
  },
29
30
  get url() {
30
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
31
+ let path = this[incomingKey]["path"];
32
+ if (!path) {
33
+ const originalPath = this[incomingKey].url;
34
+ path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
35
+ this[incomingKey]["path"] = path;
36
+ }
37
+ return `http://${this[incomingKey].headers.host}${path}`;
31
38
  },
32
39
  [getRequestCache]() {
33
40
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/listener.js CHANGED
@@ -35,6 +35,7 @@ __export(listener_exports, {
35
35
  module.exports = __toCommonJS(listener_exports);
36
36
 
37
37
  // src/request.ts
38
+ var import_node_path = require("path");
38
39
  var import_node_stream = require("stream");
39
40
  var newRequestFromIncoming = (method, url, incoming) => {
40
41
  const headerRecord = [];
@@ -60,7 +61,13 @@ var requestPrototype = {
60
61
  return this[incomingKey].method || "GET";
61
62
  },
62
63
  get url() {
63
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
64
+ let path = this[incomingKey]["path"];
65
+ if (!path) {
66
+ const originalPath = this[incomingKey].url;
67
+ path = /\.\./.test(originalPath) ? (0, import_node_path.resolve)(originalPath) : originalPath;
68
+ this[incomingKey]["path"] = path;
69
+ }
70
+ return `http://${this[incomingKey].headers.host}${path}`;
64
71
  },
65
72
  [getRequestCache]() {
66
73
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/listener.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/request.ts
2
+ import { resolve } from "path";
2
3
  import { Readable } from "stream";
3
4
  var newRequestFromIncoming = (method, url, incoming) => {
4
5
  const headerRecord = [];
@@ -24,7 +25,13 @@ var requestPrototype = {
24
25
  return this[incomingKey].method || "GET";
25
26
  },
26
27
  get url() {
27
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
28
+ let path = this[incomingKey]["path"];
29
+ if (!path) {
30
+ const originalPath = this[incomingKey].url;
31
+ path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
32
+ this[incomingKey]["path"] = path;
33
+ }
34
+ return `http://${this[incomingKey].headers.host}${path}`;
28
35
  },
29
36
  [getRequestCache]() {
30
37
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/request.js CHANGED
@@ -23,6 +23,7 @@ __export(request_exports, {
23
23
  newRequest: () => newRequest
24
24
  });
25
25
  module.exports = __toCommonJS(request_exports);
26
+ var import_node_path = require("path");
26
27
  var import_node_stream = require("stream");
27
28
  var newRequestFromIncoming = (method, url, incoming) => {
28
29
  const headerRecord = [];
@@ -48,7 +49,13 @@ var requestPrototype = {
48
49
  return this[incomingKey].method || "GET";
49
50
  },
50
51
  get url() {
51
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
52
+ let path = this[incomingKey]["path"];
53
+ if (!path) {
54
+ const originalPath = this[incomingKey].url;
55
+ path = /\.\./.test(originalPath) ? (0, import_node_path.resolve)(originalPath) : originalPath;
56
+ this[incomingKey]["path"] = path;
57
+ }
58
+ return `http://${this[incomingKey].headers.host}${path}`;
52
59
  },
53
60
  [getRequestCache]() {
54
61
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/request.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/request.ts
2
+ import { resolve } from "path";
2
3
  import { Readable } from "stream";
3
4
  var newRequestFromIncoming = (method, url, incoming) => {
4
5
  const headerRecord = [];
@@ -24,7 +25,13 @@ var requestPrototype = {
24
25
  return this[incomingKey].method || "GET";
25
26
  },
26
27
  get url() {
27
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
28
+ let path = this[incomingKey]["path"];
29
+ if (!path) {
30
+ const originalPath = this[incomingKey].url;
31
+ path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
32
+ this[incomingKey]["path"] = path;
33
+ }
34
+ return `http://${this[incomingKey].headers.host}${path}`;
28
35
  },
29
36
  [getRequestCache]() {
30
37
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
@@ -1,4 +1,4 @@
1
- import { MiddlewareHandler } from 'hono';
1
+ import { Context, MiddlewareHandler } from 'hono';
2
2
 
3
3
  type ServeStaticOptions = {
4
4
  /**
@@ -8,6 +8,7 @@ type ServeStaticOptions = {
8
8
  path?: string;
9
9
  index?: string;
10
10
  rewriteRequestPath?: (path: string) => string;
11
+ onNotFound?: (path: string, c: Context) => void | Promise<void>;
11
12
  };
12
13
  declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
13
14
 
@@ -1,4 +1,4 @@
1
- import { MiddlewareHandler } from 'hono';
1
+ import { Context, MiddlewareHandler } from 'hono';
2
2
 
3
3
  type ServeStaticOptions = {
4
4
  /**
@@ -8,6 +8,7 @@ type ServeStaticOptions = {
8
8
  path?: string;
9
9
  index?: string;
10
10
  rewriteRequestPath?: (path: string) => string;
11
+ onNotFound?: (path: string, c: Context) => void | Promise<void>;
11
12
  };
12
13
  declare const serveStatic: (options?: ServeStaticOptions) => MiddlewareHandler;
13
14
 
@@ -171,6 +171,7 @@ var serveStatic = (options = { root: "" }) => {
171
171
  return next();
172
172
  path = `./${path}`;
173
173
  if (!(0, import_fs.existsSync)(path)) {
174
+ await options.onNotFound?.(path, c);
174
175
  return next();
175
176
  }
176
177
  const mimeType = getMimeType(path);
@@ -147,6 +147,7 @@ var serveStatic = (options = { root: "" }) => {
147
147
  return next();
148
148
  path = `./${path}`;
149
149
  if (!existsSync(path)) {
150
+ await options.onNotFound?.(path, c);
150
151
  return next();
151
152
  }
152
153
  const mimeType = getMimeType(path);
package/dist/server.js CHANGED
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(server_exports);
37
37
  var import_node_http = require("http");
38
38
 
39
39
  // src/request.ts
40
+ var import_node_path = require("path");
40
41
  var import_node_stream = require("stream");
41
42
  var newRequestFromIncoming = (method, url, incoming) => {
42
43
  const headerRecord = [];
@@ -62,7 +63,13 @@ var requestPrototype = {
62
63
  return this[incomingKey].method || "GET";
63
64
  },
64
65
  get url() {
65
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
66
+ let path = this[incomingKey]["path"];
67
+ if (!path) {
68
+ const originalPath = this[incomingKey].url;
69
+ path = /\.\./.test(originalPath) ? (0, import_node_path.resolve)(originalPath) : originalPath;
70
+ this[incomingKey]["path"] = path;
71
+ }
72
+ return `http://${this[incomingKey].headers.host}${path}`;
66
73
  },
67
74
  [getRequestCache]() {
68
75
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/server.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  import { createServer as createServerHTTP } from "http";
3
3
 
4
4
  // src/request.ts
5
+ import { resolve } from "path";
5
6
  import { Readable } from "stream";
6
7
  var newRequestFromIncoming = (method, url, incoming) => {
7
8
  const headerRecord = [];
@@ -27,7 +28,13 @@ var requestPrototype = {
27
28
  return this[incomingKey].method || "GET";
28
29
  },
29
30
  get url() {
30
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
31
+ let path = this[incomingKey]["path"];
32
+ if (!path) {
33
+ const originalPath = this[incomingKey].url;
34
+ path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
35
+ this[incomingKey]["path"] = path;
36
+ }
37
+ return `http://${this[incomingKey].headers.host}${path}`;
31
38
  },
32
39
  [getRequestCache]() {
33
40
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/vercel.js CHANGED
@@ -35,6 +35,7 @@ __export(vercel_exports, {
35
35
  module.exports = __toCommonJS(vercel_exports);
36
36
 
37
37
  // src/request.ts
38
+ var import_node_path = require("path");
38
39
  var import_node_stream = require("stream");
39
40
  var newRequestFromIncoming = (method, url, incoming) => {
40
41
  const headerRecord = [];
@@ -60,7 +61,13 @@ var requestPrototype = {
60
61
  return this[incomingKey].method || "GET";
61
62
  },
62
63
  get url() {
63
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
64
+ let path = this[incomingKey]["path"];
65
+ if (!path) {
66
+ const originalPath = this[incomingKey].url;
67
+ path = /\.\./.test(originalPath) ? (0, import_node_path.resolve)(originalPath) : originalPath;
68
+ this[incomingKey]["path"] = path;
69
+ }
70
+ return `http://${this[incomingKey].headers.host}${path}`;
64
71
  },
65
72
  [getRequestCache]() {
66
73
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/dist/vercel.mjs CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/request.ts
2
+ import { resolve } from "path";
2
3
  import { Readable } from "stream";
3
4
  var newRequestFromIncoming = (method, url, incoming) => {
4
5
  const headerRecord = [];
@@ -24,7 +25,13 @@ var requestPrototype = {
24
25
  return this[incomingKey].method || "GET";
25
26
  },
26
27
  get url() {
27
- return `http://${this[incomingKey].headers.host}${this[incomingKey].url}`;
28
+ let path = this[incomingKey]["path"];
29
+ if (!path) {
30
+ const originalPath = this[incomingKey].url;
31
+ path = /\.\./.test(originalPath) ? resolve(originalPath) : originalPath;
32
+ this[incomingKey]["path"] = path;
33
+ }
34
+ return `http://${this[incomingKey].headers.host}${path}`;
28
35
  },
29
36
  [getRequestCache]() {
30
37
  return this[requestCache] ||= newRequestFromIncoming(this.method, this.url, this[incomingKey]);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.3.5",
3
+ "version": "1.4.1",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",