test: disable directoryImport in test env
This commit is contained in:
+40
-4
@@ -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<string, { route: Route } | { namespace: Namespace }> = {};
|
||||
|
||||
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),
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user