Skip to content

Commit

Permalink
feat: added middleware possibility to route builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Nino van Galen committed Jun 23, 2020
1 parent 10c539c commit 099ae3c
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/server/routers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,20 @@ const bindRoute = (http, route, parentPath = '') => {
route.args.public = true;
}

http[route.method](localPath, async (...args) => {
const callable = route.controller;
if (isPromise(callable)) {
await callable(...args).catch(args[args.length - 1]);
return;
}
http[route.method](localPath, ...(Array.isArray(route.controller) ? route.controller : [route.controller])
.map((controller) => async (...args) => {
const callable = controller;
if (isPromise(callable)) {
await callable(...args).catch(args[args.length - 1]);
return;
}

try {
callable(...args);
} catch (error) {
args[args.length - 1](error);
}
}, route.args);
try {
callable(...args);
} catch (error) {
args[args.length - 1](error);
}
}), route.args);
}

if (route.children) {
Expand Down

0 comments on commit 099ae3c

Please sign in to comment.