| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- /**
- * 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.7/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.1/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());
- let createTikHubRoutes;
- try {
- ({ createTikHubRoutes } = await globalThis.loadModule(
- 'https://repos.fmode.cn/x/fmode-tikhub-api/0.0.1/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;
|