|
1 | | -import type { Context, MiddlewareHandler } from 'hono' |
| 1 | +import type { Context, Env, MiddlewareHandler } from 'hono' |
2 | 2 | import { getFilePath, getFilePathWithoutDefaultDocument } from 'hono/utils/filepath' |
3 | 3 | import { getMimeType } from 'hono/utils/mime' |
4 | 4 | import { createReadStream, lstatSync } from 'fs' |
5 | 5 | import type { ReadStream, Stats } from 'fs' |
6 | 6 |
|
7 | | -export type ServeStaticOptions = { |
| 7 | +export type ServeStaticOptions<E extends Env = Env> = { |
8 | 8 | /** |
9 | 9 | * Root path, relative to current working directory from which the app was started. Absolute paths are not supported. |
10 | 10 | */ |
11 | 11 | root?: string |
12 | 12 | path?: string |
13 | 13 | index?: string // default is 'index.html' |
14 | 14 | rewriteRequestPath?: (path: string) => string |
15 | | - onNotFound?: (path: string, c: Context) => void | Promise<void> |
| 15 | + onFound?: (path: string, c: Context<E>) => void | Promise<void> |
| 16 | + onNotFound?: (path: string, c: Context<E>) => void | Promise<void> |
16 | 17 | } |
17 | 18 |
|
18 | 19 | const createStreamBody = (stream: ReadStream) => { |
@@ -87,6 +88,7 @@ export const serveStatic = (options: ServeStaticOptions = { root: '' }): Middlew |
87 | 88 | await options.onNotFound?.(path, c) |
88 | 89 | return next() |
89 | 90 | } |
| 91 | + await options.onFound?.(path, c) |
90 | 92 |
|
91 | 93 | const mimeType = getMimeType(path) |
92 | 94 | if (mimeType) { |
|
0 commit comments