routes.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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.4/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 dllfb0npquu1rgqwcw9yb0uynndwzz09',
  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. /* 已清洗的社媒接口 */
  59. let createTikHubCustomizeRoutes;
  60. try {
  61. ({ createTikHubCustomizeRoutes } = await globalThis.loadModule(
  62. 'https://repos.fmode.cn/x/fmode-tikhub-api-customize/0.1.2/fmode-tikhub-api-customize.min.js?code=xxxxxxx'
  63. ));
  64. } catch (e) {
  65. console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
  66. ({ createTikHubCustomizeRoutes } = await import('../modules/fmode-tikhub-server/src/mod'));
  67. }
  68. router.use(
  69. '/tikhubCustomize',
  70. createTikHubCustomizeRoutes({
  71. serverURL: 'https://server.fmode.cn/thapi/v1',
  72. apiKey: 'tKIbAsEM8X+GmE2vHqGW7D/ICwK1Q5V4viKFrWiPB6HholGdLFqZJmmyNw=='
  73. })
  74. );
  75. // 挂载飞书模块路由(新版 fmode-feishu-api)
  76. let createFeishuRouter;
  77. try {
  78. ({ createFeishuRouter } = await globalThis.loadModule(
  79. 'https://repos.fmode.cn/x/fmode-feishu-api/0.0.1/fmode-feishu-api.min.js?code=xxxxxxx'
  80. ));
  81. } catch (e) {
  82. console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
  83. ({ createFeishuRouter } = await import('../modules/fmode-feishu-api/src/router.ts'));
  84. }
  85. router.use(
  86. '/feishu-v2',
  87. createFeishuRouter({
  88. 'cli_a9253658eef99cd2': {
  89. appId: 'cli_a9253658eef99cd2',
  90. appSecret: '9ci7yeo4bA81ew63gC1OHhbhVWlNb2yx',
  91. enabled: true,
  92. environment: 'development'
  93. }
  94. })
  95. )
  96. // let createPinterestRouter;
  97. // try {
  98. // ({ createPinterestRouter } = await globalThis.loadModule(
  99. // 'https://repos.fmode.cn/x/fmode-brightdata-api/0.0.1/fmode-brightdata-api.min.js?code=xxxxxxx'
  100. // ));
  101. // } catch (e) {
  102. // console.warn("[API Routes] CDN 加载失败, 使用本地模块回退", e);
  103. // // ({ createPinterestRouter } = await import('../modules/fmode-brightdata-server/src/mod.ts'));
  104. // }
  105. // router.use('/pinterest', createPinterestRouter());
  106. router.get('/', (req, res) => {
  107. res.json({
  108. message: 'API Routes Loaded Successfully',
  109. version: '1.0.0',
  110. timestamp: new Date().toISOString(),
  111. availableRoutes: [
  112. '/api/amazon',
  113. '/api/amazon/test',
  114. '/api/sorftime',
  115. '/api/sorftime/test',
  116. '/api/tikhub',
  117. '/api/tikhub/health',
  118. // '/api/pinterest',
  119. // '/api/pinterest/search'
  120. ]
  121. });
  122. });
  123. export default router;