| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- /**
- * API 路由主入口
- * 手动加载并挂载所有子路由模块
- */
- import express from 'npm:express';
- // 创建主路由
- const router = express.Router();
- console.log('[API Routes] Initializing...');
- // Debug middleware
- router.use((req, res, next) => {
- console.log(`[API Router] Hit: ${req.method} ${req.url} (Original: ${req.originalUrl})`);
- next();
- });
- router.get('/ping', (req, res) => {
- res.json({ message: 'pong' });
- });
- let createSpApiRouter;
- try {
- ({ createSpApiRouter } = await globalThis.loadModule(
- "https://repos.fmode.cn/x/fmode-amazon-sp-api/0.0.9/fmode-amazon-sp-api.min.js?code=xxxxxxx"
- ));
- } catch (e) {
- console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
- // ({ createSpApiRouter } = await import("../modules/fmode-amazon-sp-api/src/mod.ts"));
- }
- // 本地开发模式加载
- //const { createSpApiRouter } = await import("../modules/fmode-amazon-sp-api/src/mod.ts");
- // 挂载 SP-API 路由
- router.use('/amazon', createSpApiRouter());
- let createSorftimeRouter;
- try {
- ({ createSorftimeRouter } = await globalThis.loadModule(
- 'https://repos.fmode.cn/x/fmode-sorftime-api/0.0.3/fmode-sorftime-api.min.js?code=xxxxxxx'
- ));
- } catch (e) {
- console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
- // ({ createSorftimeRouter } = await import('../modules/fmode-sorftime-api/src/mod.ts'));
- }
- router.use('/sorftime', createSorftimeRouter({
- token: 'BasicAuth nlbuzstvrkwyadzyee5kwfrtqkc4zz09',
- }));
- let createTikHubRoutes;
- try {
- ({ createTikHubRoutes } = await globalThis.loadModule(
- 'https://repos.fmode.cn/x/fmode-tikhub-api/0.0.2/fmode-tikhub-api.min.js?code=xxxxxxx'
- ));
- } catch (e) {
- console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
- // ({ createTikHubRoutes } = await import('../modules/fmode-tikhub-api/src/mod.ts'));
- }
- router.use(
- '/tikhub',
- createTikHubRoutes({
- basePath: '/api/tikhub',
- apiKey: 'tKIbAsEM8X+GmE2vHqGW7D/ICwK1Q5V4viKFrWiPB6HholGdLFqZJmmyNw=='
- })
- );
- router.get('/', (req, res) => {
- res.json({
- message: 'API Routes Loaded Successfully',
- version: '1.0.0',
- timestamp: new Date().toISOString(),
- availableRoutes: [
- '/api/amazon',
- '/api/amazon/test',
- '/api/sorftime',
- '/api/sorftime/test',
- '/api/tikhub',
- '/api/tikhub/health'
- ]
- });
- });
- export default router;
|