mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-14 09:12:01 +08:00
feat(core): first attempt to init script standard (#8224)
- lazy load - rate limit per path - init .debug.json support - docs - maintainer - radar
This commit is contained in:
@@ -1,24 +1,6 @@
|
||||
const Router = require('@koa/router');
|
||||
const config = require('@/config').value;
|
||||
const router = new Router();
|
||||
|
||||
// 遍历整个 routes 文件夹,导入模块路由 router.js 和 router-custom.js 文件
|
||||
// 格式参考用例:routes/epicgames/router.js
|
||||
const RouterPath = require('require-all')({
|
||||
dirname: __dirname + '/routes',
|
||||
filter: /^.*router([-_]custom[s]?)?\.js$/,
|
||||
});
|
||||
|
||||
// 将收集到的自定义模块路由进行合并
|
||||
for (const project in RouterPath) {
|
||||
for (const routerName in RouterPath[project]) {
|
||||
const proRouter = RouterPath[project][routerName]();
|
||||
proRouter.stack.forEach((nestedLayer) => {
|
||||
router.stack.push(nestedLayer);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const RouterHandlerMap = new Map();
|
||||
|
||||
// 懒加载 Route Handler,Route 首次被请求时才会 require 相关文件
|
||||
@@ -32,20 +14,7 @@ const lazyloadRouteHandler = (routeHandlerPath) => (ctx) => {
|
||||
return handler(ctx);
|
||||
};
|
||||
|
||||
// index
|
||||
router.get('/', lazyloadRouteHandler('./routes/index'));
|
||||
|
||||
router.get('/robots.txt', (ctx) => {
|
||||
if (config.disallowRobot) {
|
||||
ctx.set('Content-Type', 'text/plain');
|
||||
ctx.body = 'User-agent: *\nDisallow: /';
|
||||
} else {
|
||||
ctx.throw(404, 'Not Found');
|
||||
}
|
||||
});
|
||||
|
||||
// test
|
||||
router.get('/test/:id', lazyloadRouteHandler('./routes/test'));
|
||||
// Deprecated: DO NOT ADD ROUTE HERE
|
||||
|
||||
// RSSHub
|
||||
router.get('/rsshub/rss', lazyloadRouteHandler('./routes/rsshub/routes')); // 弃用
|
||||
@@ -3234,11 +3203,6 @@ router.get('/liequtv/room/:id', lazyloadRouteHandler('./routes/liequtv/room'));
|
||||
// Behance
|
||||
router.get('/behance/:user/:type?', lazyloadRouteHandler('./routes/behance/index'));
|
||||
|
||||
// furstar.jp
|
||||
router.get('/furstar/characters/:lang?', lazyloadRouteHandler('./routes/furstar/index'));
|
||||
router.get('/furstar/artists/:lang?', lazyloadRouteHandler('./routes/furstar/artists'));
|
||||
router.get('/furstar/archive/:lang?', lazyloadRouteHandler('./routes/furstar/archive'));
|
||||
|
||||
// 北京物资学院
|
||||
router.get('/bwu/news', lazyloadRouteHandler('./routes/universities/bwu/news'));
|
||||
|
||||
@@ -4149,7 +4113,7 @@ router.get('/ehentai/search/:params?/:page?/:bittorrent?', lazyloadRouteHandler(
|
||||
router.get('/ehentai/tag/:tag/:page?/:bittorrent?', lazyloadRouteHandler('./routes/ehentai/tag'));
|
||||
|
||||
// 字型故事
|
||||
router.get('/fontstory', require('./routes/fontstory/tw'));
|
||||
router.get('/fontstory', lazyloadRouteHandler('./routes/fontstory/tw'));
|
||||
|
||||
// HKEPC
|
||||
router.get('/hkepc/:category?', lazyloadRouteHandler('./routes/hkepc/index'));
|
||||
@@ -4248,4 +4212,6 @@ router.get('/hket/:category?', lazyloadRouteHandler('./routes/hket/index'));
|
||||
// s-hentai
|
||||
router.get('/s-hentai/:id?', lazyloadRouteHandler('./routes/s-hentai'));
|
||||
|
||||
// Deprecated: DO NOT ADD ROUTE HERE
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user