Skip to content

Commit

Permalink
exit handler before loop if no middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jan 17, 2018
1 parent 9c6a470 commit ded9d0b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ class Polka extends Router {
req.pathname = info.pathname;
req.search = info.search;
req.query = info.query;

// Loop thru all middlware
// Exit if no middleware
let i=0, arr=this.wares, len=arr.length;
if (len === i) return obj.handler(req, res);
// Otherwise loop thru all middlware
let next = err => err ? this.send(res, err.code || 500, err.toString()) : loop();
let loop = _ => res.finished || (i < len) ? arr[i++](req, res, next) : obj.handler(req, res);

loop(); // init
}
}
Expand Down

0 comments on commit ded9d0b

Please sign in to comment.