Skip to content

Commit

Permalink
Fix issue with router() not returning matches
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie committed Mar 2, 2022
1 parent bc917eb commit b3b1e37
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/zap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,14 @@ export function notFound() {

// Router ----------------------------------------------------------------------

export function router(...handlers: RouteHandler<HttpMethod, any, ResponseBodyType>[]) {
return async function (req: ServerRequest, res: ServerResponse) {
export function router(...handlers: RouteHandler<HttpMethod, any, ResponseBodyType>[]): 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<any>, res)
return await current(req as ServerRequest<any>, res)
}
return send(res, 404, 'Not Found')
}
Expand Down

0 comments on commit b3b1e37

Please sign in to comment.