Files
RSSHub/api_router.js
2018-09-11 11:04:49 +08:00

35 lines
877 B
JavaScript

const Router = require('koa-router');
const router = new Router();
const routes = require('./router');
router.get('/routes/:name?', (ctx) => {
const allRoutes = Array.from(routes.stack);
allRoutes.shift();
const result = {};
allRoutes.forEach((i) => {
const path = i.path;
const top = path.split('/')[1];
if (ctx.params.name === undefined) {
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] };
}
}
}
});
ctx.body = result;
});
module.exports = router;