(routes: HonoRoute[])
| 116 | * See: https://github.com/honojs/hono/blob/18fe604c8cefc2628240651b1af219692e1918c1/src/hono-base.ts#L156-L168 |
| 117 | */ |
| 118 | export function wrapSubAppMiddleware(routes: HonoRoute[]): void { |
| 119 | const lastIndexByKey = new Map<string, number>(); |
| 120 | for (const [i, route] of routes.entries()) { |
| 121 | // \0 (null byte) is a collision-free delimiter: it cannot appear in a valid HTTP method name or URL path |
| 122 | lastIndexByKey.set(`${route.method}\0${route.path}`, i); |
| 123 | } |
| 124 | |
| 125 | for (const [i, route] of routes.entries()) { |
| 126 | if (typeof route.handler !== 'function') { |
| 127 | continue; |
| 128 | } |
| 129 | |
| 130 | const isLastForGroup = lastIndexByKey.get(`${route.method}\0${route.path}`) === i; |
| 131 | |
| 132 | const isMW = !isLastForGroup || (route.method === 'ALL' && isMiddleware(route.handler)); |
| 133 | if (isMW) { |
| 134 | route.handler = wrapMiddlewareWithSpan(route.handler); |
| 135 | } |
| 136 | } |
| 137 | } |
no test coverage detected