(app: Hono<E>)
| 17 | * Idempotent. |
| 18 | */ |
| 19 | export function patchAppUse<E extends Env>(app: Hono<E>): void { |
| 20 | if (patchedUseInstances.has(app)) { |
| 21 | DEBUG_BUILD && debug.log('[hono] app.use already patched — skipping.'); |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | patchedUseInstances.add(app); |
| 26 | |
| 27 | app.use = new Proxy(app.use, { |
| 28 | apply(target: typeof app.use, thisArg: typeof app, args: Parameters<typeof app.use>): ReturnType<typeof app.use> { |
| 29 | const [first, ...rest] = args as [unknown, ...MiddlewareHandler[]]; |
| 30 | |
| 31 | if (typeof first === 'string') { |
| 32 | const wrappedHandlers = rest.map(handler => wrapMiddlewareWithSpan(handler)); |
| 33 | return Reflect.apply(target, thisArg, [first, ...wrappedHandlers]); |
| 34 | } |
| 35 | |
| 36 | const allHandlers = [first as MiddlewareHandler, ...rest].map(handler => wrapMiddlewareWithSpan(handler)); |
| 37 | return Reflect.apply(target, thisArg, allHandlers); |
| 38 | }, |
| 39 | }); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Patches HTTP method class fields (get, post, put, delete, options, patch, all) to instrument inline middleware at registration time. |
no test coverage detected