routes.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /**
  2. * API 路由主入口
  3. * 手动加载并挂载所有子路由模块
  4. */
  5. import express from 'npm:express';
  6. // 创建主路由
  7. const router = express.Router();
  8. console.log('[API Routes] Initializing...');
  9. // Debug middleware
  10. router.use((req, res, next) => {
  11. console.log(`[API Router] Hit: ${req.method} ${req.url} (Original: ${req.originalUrl})`);
  12. next();
  13. });
  14. router.get('/ping', (req, res) => {
  15. res.json({ message: 'pong' });
  16. });
  17. let createSpApiRouter;
  18. try {
  19. ({ createSpApiRouter } = await globalThis.loadModule(
  20. "https://repos.fmode.cn/x/fmode-amazon-sp-api/0.0.9/fmode-amazon-sp-api.min.js?code=xxxxxxx"
  21. ));
  22. } catch (e) {
  23. console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
  24. // ({ createSpApiRouter } = await import("../modules/fmode-amazon-sp-api/src/mod.ts"));
  25. }
  26. // 本地开发模式加载
  27. //const { createSpApiRouter } = await import("../modules/fmode-amazon-sp-api/src/mod.ts");
  28. // 挂载 SP-API 路由
  29. router.use('/amazon', createSpApiRouter());
  30. let createSorftimeRouter;
  31. try {
  32. ({ createSorftimeRouter } = await globalThis.loadModule(
  33. 'https://repos.fmode.cn/x/fmode-sorftime-api/0.0.3/fmode-sorftime-api.min.js?code=xxxxxxx'
  34. ));
  35. } catch (e) {
  36. console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
  37. // ({ createSorftimeRouter } = await import('../modules/fmode-sorftime-api/src/mod.ts'));
  38. }
  39. router.use('/sorftime', createSorftimeRouter({
  40. token: 'BasicAuth nlbuzstvrkwyadzyee5kwfrtqkc4zz09',
  41. }));
  42. let createTikHubRoutes;
  43. try {
  44. ({ createTikHubRoutes } = await globalThis.loadModule(
  45. 'https://repos.fmode.cn/x/fmode-tikhub-api/0.0.2/fmode-tikhub-api.min.js?code=xxxxxxx'
  46. ));
  47. } catch (e) {
  48. console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
  49. // ({ createTikHubRoutes } = await import('../modules/fmode-tikhub-api/src/mod.ts'));
  50. }
  51. router.use(
  52. '/tikhub',
  53. createTikHubRoutes({
  54. basePath: '/api/tikhub',
  55. apiKey: 'tKIbAsEM8X+GmE2vHqGW7D/ICwK1Q5V4viKFrWiPB6HholGdLFqZJmmyNw=='
  56. })
  57. );
  58. router.get('/', (req, res) => {
  59. res.json({
  60. message: 'API Routes Loaded Successfully',
  61. version: '1.0.0',
  62. timestamp: new Date().toISOString(),
  63. availableRoutes: [
  64. '/api/amazon',
  65. '/api/amazon/test',
  66. '/api/sorftime',
  67. '/api/sorftime/test',
  68. '/api/tikhub',
  69. '/api/tikhub/health'
  70. ]
  71. });
  72. });
  73. export default router;