diff --git a/src/zap.ts b/src/zap.ts index c1debe1..5b8e8ed 100644 --- a/src/zap.ts +++ b/src/zap.ts @@ -206,14 +206,14 @@ export function notFound() { // Router ---------------------------------------------------------------------- -export function router(...handlers: RouteHandler[]) { - return async function (req: ServerRequest, res: ServerResponse) { +export function router(...handlers: RouteHandler[]): Handler { + return async function (req, res) { for (const current of handlers) { if (req.method !== current.method) continue const match = current.matchPath(req.parsedURL.pathname) if (!match) continue req.params = match.params - await current(req as ServerRequest, res) + return await current(req as ServerRequest, res) } return send(res, 404, 'Not Found') }