| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- /**
- * API 路由主入口(客户独立实例)
- * - Amazon:保留本地 SP-API 模块
- * - Sorftime / TikHub:仅走公司中转 Relay(src/relay + api/relay)
- * - 已移除:直连 sorftime / tikhub / eccang 模块
- */
- import express from 'npm:express';
- const router = express.Router();
- console.log('[API Routes] Initializing TARGET customer instance...');
- 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', instance: 'TARGET-voc-instance' });
- });
- /**
- * 亚马逊相关接口
- * 必须携带店铺的 id
- */
- let createSpApiRouter;
- try {
- ({ createSpApiRouter } = await globalThis.loadModule(
- 'https://repos.fmode.cn/x/fmode-amazon-sp-api/0.1.3/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'));
- }
- router.use('/amazon', createSpApiRouter());
- /**
- * Sorftime / TikHub:公司中转 Relay
- * 对外契约:
- * POST /api/sorftime/forward
- * POST /api/tikhub/forward
- */
- import sorftimeRelayRouter from './relay/sorftime-routes.ts';
- import tikhubRelayRouter from './relay/tikhub-routes.ts';
- router.use('/sorftime', sorftimeRelayRouter);
- router.use('/tikhub', tikhubRelayRouter);
- console.log('[API Routes] ✅ Sorftime/TikHub relay mounted (company server.fmode.cn)');
- // 定时任务管理路由(内部已改为打本机 /api/sorftime/forward)
- import scheduleRouter from './module/schedule/routes-schedule.ts';
- try {
- router.use('/schedule', scheduleRouter);
- } catch (e) {
- console.warn('[API Routes] scheduleRouter 加载失败', e);
- }
- router.get('/', (req, res) => {
- res.json({
- message: 'TARGET VOC Instance API Routes Loaded',
- version: '1.0.1-customer-relay',
- timestamp: new Date().toISOString(),
- availableRoutes: [
- '/api/amazon',
- '/api/sorftime/forward',
- '/api/sorftime/health',
- '/api/tikhub/forward',
- '/api/tikhub/health',
- '/api/schedule',
- ],
- removedModules: [
- 'fmode-sorftime-api (direct upstream)',
- 'fmode-tikhub-api (direct upstream)',
- 'fmode-tikhub-api-customize',
- 'fmode-eccang-api',
- ],
- relay: {
- companyBase: 'https://server.fmode.cn',
- sorftimeUpstream: '/api/voc-ecom/forward',
- tikhubUpstream: '/api/voc-social/*',
- },
- });
- });
- export default router;
|