diff --git a/lib/init-routes.test.ts b/lib/registry.test.ts similarity index 100% rename from lib/init-routes.test.ts rename to lib/registry.test.ts diff --git a/lib/registry.ts b/lib/registry.ts index e36dcbfb7..c6f388273 100644 --- a/lib/registry.ts +++ b/lib/registry.ts @@ -2,11 +2,35 @@ import type { Namespace, Route } from '@/types'; import { directoryImport } from 'directory-import'; import type { Hono, Handler } from 'hono'; import * as path from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { serveStatic } from '@hono/node-server/serve-static'; -const modules = directoryImport({ - targetDirectoryPath: path.join(__dirname, './routes-new'), - importPattern: /\.ts$/, -}); +import index from '@/routes/index'; +import robotstxt from '@/routes/robots.txt'; +import { namespace as testNamespace } from './routes-new/test/namespace'; +import { route as testRoute } from '@/routes-new/test/index'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); + +let modules: Record = {}; + +switch (process.env.NODE_ENV) { + case 'test': + modules = { + '/test/namespace.ts': { + namespace: testNamespace, + }, + '/test/index.ts': { + route: testRoute, + }, + }; + break; + default: + modules = directoryImport({ + targetDirectoryPath: path.join(__dirname, './routes-new'), + importPattern: /\.ts$/, + }) as typeof modules; +} const namespaces: Record< string, @@ -63,4 +87,16 @@ export default function (app: Hono) { subApp.get(path, wrapedHandler); } } + + // routes without rss data + app.get('/', index); + app.get('/robots.txt', robotstxt); + + app.use( + '/*', + serveStatic({ + root: './lib/assets', + rewriteRequestPath: (path) => (path === '/favicon.ico' ? '/favicon.png' : path), + }) + ); } diff --git a/lib/routes-new/test/index.ts b/lib/routes-new/test/index.ts index fbf581b75..7505c8874 100644 --- a/lib/routes-new/test/index.ts +++ b/lib/routes-new/test/index.ts @@ -7,11 +7,11 @@ import { DataItem, Route } from '@/types'; let cacheIndex = 0; export const route: Route = { - path: '/bangumi/media/:mediaid', - categories: ['new-media'], - example: '/bilibili/bangumi/media/9192', + path: '/:id', + categories: ['other'], + example: '/test/1', parameters: { - mediaid: '番剧媒体 id, 番剧主页 URL 中获取', + id: 'test id', }, features: { requireConfig: false, @@ -22,12 +22,8 @@ export const route: Route = { supportPodcast: false, supportScihub: false, }, - name: '番剧', + name: 'Test', maintainers: ['DIYgod'], - radar: { - source: ['www.bilibili.com/bangumi/media/:bid'], - target: '/bangumi/media/:bid', - }, handler, };