Skip to content

Commit

Permalink
Refactoring assignment of req.last to be the first non-blacklisted …
Browse files Browse the repository at this point in the history
…HTTP method specific handler
  • Loading branch information
avoidwork committed Oct 24, 2019
1 parent 79f5b41 commit 5237a6c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions lib/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,17 @@ function reduce (uri, map = new Map(), arg = {}, end = false) {

return i[0].test(uri);
}).forEach(i => {
arg.middleware = [...arg.middleware, ...i[1].handlers];
const handlers = i[1].handlers;

if (end) {
arg.last = arg.middleware[arg.middleware.length - 1];
arg.middleware = [...arg.middleware, ...handlers];

if (end && arg.last === null) {
for (const fn of handlers) {
if ("blacklisted" in fn === false) {
arg.last = fn;
break;
}
}
}

if (i[1].pos.length > 0 && arg.pos.length === 0) {
Expand Down
1 change: 1 addition & 0 deletions lib/woodland.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Woodland extends EventEmitter {
}

blacklist (fn) {
fn.blacklisted = true;
this.blacklisted.add(fn);

return this;
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "woodland",
"version": "9.1.2",
"version": "9.1.3",
"description": "Lightweight HTTP/HTTP2 router with automatic `Allow` & `CORS` headers",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 5237a6c

Please sign in to comment.