mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-03 10:38:03 +08:00
optimize directory structure
This commit is contained in:
28
lib/api_router.js
Normal file
28
lib/api_router.js
Normal file
@@ -0,0 +1,28 @@
|
||||
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 = {};
|
||||
let counter = 0;
|
||||
|
||||
allRoutes.forEach((i) => {
|
||||
const path = i.path;
|
||||
const top = path.split('/')[1];
|
||||
|
||||
if (!ctx.params.name || top === ctx.params.name) {
|
||||
if (result[top]) {
|
||||
result[top].routes.push(path);
|
||||
} else {
|
||||
result[top] = { routes: [path] };
|
||||
}
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
|
||||
ctx.body = { counter, result };
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
Reference in New Issue
Block a user