Skip to content

Commit 099ae3c

Browse files
author
Nino van Galen
committed
feat: added middleware possibility to route builder
1 parent 10c539c commit 099ae3c

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

lib/server/routers/index.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,19 +66,20 @@ const bindRoute = (http, route, parentPath = '') => {
6666
route.args.public = true;
6767
}
6868

69-
http[route.method](localPath, async (...args) => {
70-
const callable = route.controller;
71-
if (isPromise(callable)) {
72-
await callable(...args).catch(args[args.length - 1]);
73-
return;
74-
}
69+
http[route.method](localPath, ...(Array.isArray(route.controller) ? route.controller : [route.controller])
70+
.map((controller) => async (...args) => {
71+
const callable = controller;
72+
if (isPromise(callable)) {
73+
await callable(...args).catch(args[args.length - 1]);
74+
return;
75+
}
7576

76-
try {
77-
callable(...args);
78-
} catch (error) {
79-
args[args.length - 1](error);
80-
}
81-
}, route.args);
77+
try {
78+
callable(...args);
79+
} catch (error) {
80+
args[args.length - 1](error);
81+
}
82+
}), route.args);
8283
}
8384

8485
if (route.children) {

0 commit comments

Comments
 (0)