(req: HTTPRequestLike, res: HTTPResponseLike)
| 63 | } |
| 64 | |
| 65 | async route(req: HTTPRequestLike, res: HTTPResponseLike): Promise<boolean> { |
| 66 | const pathname = parseRequestUrl(req).pathname; |
| 67 | const method = req.method as HTTPMethod; |
| 68 | |
| 69 | for (const route of this.routes) { |
| 70 | if (route.method === method) { |
| 71 | const match = pathname.match(route.regex); |
| 72 | if (match) { |
| 73 | const params: Record<string, string> = {}; |
| 74 | |
| 75 | // Extract route parameters |
| 76 | for (let i = 0; i < route.paramNames.length; i++) { |
| 77 | const paramName = route.paramNames[i]; |
| 78 | const paramValue = match[i + 1]; |
| 79 | if (paramValue) { |
| 80 | params[paramName] = decodeURIComponent(paramValue); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | // Call the handler |
| 85 | await route.handler(req, res, params); |
| 86 | return true; |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Register a controller using decorator-based routes |
no test coverage detected