From b3b1e37e6d065420992d7ef35cd85f0616282da9 Mon Sep 17 00:00:00 2001 From: Jacob Gillespie Date: Wed, 2 Mar 2022 13:26:44 +0000 Subject: [PATCH] Fix issue with `router()` not returning matches --- src/zap.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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') }