@hono/node-server 1.3.5 → 1.4.0

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>
@@ -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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hono/node-server",
3
- "version": "1.3.5",
3
+ "version": "1.4.0",
4
4
  "description": "Node.js Adapter for Hono",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",