Add middlewares for API and various improvements (#685)

This commit is contained in:
Henry Wang
2018-09-12 12:00:47 +08:00
committed by DIYgod
parent 05ca3a6930
commit c835fa5c02
6 changed files with 247 additions and 48 deletions
+4 -10
View File
@@ -6,29 +6,23 @@ router.get('/routes/:name?', (ctx) => {
const allRoutes = Array.from(routes.stack);
allRoutes.shift();
const result = {};
let counter = 0;
allRoutes.forEach((i) => {
const path = i.path;
const top = path.split('/')[1];
if (ctx.params.name === undefined) {
if (ctx.params.name === undefined || top === ctx.params.name) {
if (result[top]) {
result[top].routes.push(path);
} else {
result[top] = { routes: [path] };
}
} else {
if (top === ctx.params.name) {
if (result[top]) {
result[top].routes.push(path);
} else {
result[top] = { routes: [path] };
}
}
counter++;
}
});
ctx.body = result;
ctx.body = { counter, result };
});
module.exports = router;