2026-03-17 22:07:19 +08:00
|
|
|
|
import dotenv from 'dotenv';
|
|
|
|
|
|
import { DomainBootstrap } from './core/runtime/DomainBootstrap';
|
|
|
|
|
|
import { logger } from './utils/logger';
|
|
|
|
|
|
|
2026-03-18 09:38:09 +08:00
|
|
|
|
// App
|
|
|
|
|
|
import { app } from './app';
|
2026-03-17 22:07:19 +08:00
|
|
|
|
|
|
|
|
|
|
// Platform Connectors
|
|
|
|
|
|
import { AliExpressConnector } from './core/connectors/AliExpressConnector';
|
|
|
|
|
|
import { AmazonConnector } from './core/connectors/AmazonConnector';
|
|
|
|
|
|
import { ConnectorBus } from './core/connectors/IPlatformConnector';
|
|
|
|
|
|
import { ShopeeConnector } from './core/connectors/ShopeeConnector';
|
|
|
|
|
|
import { ShopifyConnector } from './core/connectors/ShopifyConnector';
|
|
|
|
|
|
import { TikTokConnector } from './core/connectors/TikTokConnector';
|
|
|
|
|
|
|
|
|
|
|
|
// Workers
|
|
|
|
|
|
import { startAuditWorker } from './services/AuditWorker';
|
|
|
|
|
|
import { CrawlerWorker } from './workers/CrawlerWorker';
|
|
|
|
|
|
|
|
|
|
|
|
dotenv.config();
|
|
|
|
|
|
|
|
|
|
|
|
const PORT = process.env.PORT || 3003;
|
|
|
|
|
|
|
|
|
|
|
|
// Register Platform Connectors
|
|
|
|
|
|
ConnectorBus.register(new TikTokConnector());
|
|
|
|
|
|
ConnectorBus.register(new ShopeeConnector());
|
|
|
|
|
|
ConnectorBus.register(new ShopifyConnector());
|
|
|
|
|
|
ConnectorBus.register(new AmazonConnector());
|
|
|
|
|
|
ConnectorBus.register(new AliExpressConnector());
|
|
|
|
|
|
|
|
|
|
|
|
// Start Background Workers
|
|
|
|
|
|
startAuditWorker();
|
|
|
|
|
|
CrawlerWorker.init();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* [ARCH_LIGHT_03] 全局启动流 (Global Startup Flow)
|
|
|
|
|
|
* @description 使用 DomainBootstrap 统一管理初始化,彻底解决 index.ts 膨胀与重复代码问题。
|
|
|
|
|
|
*/
|
|
|
|
|
|
async function startServer() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
// 1. 领域初始化 (含 DB 建表与 AGI 降级检查)
|
|
|
|
|
|
await DomainBootstrap.init();
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 启动 HTTP 服务
|
|
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
|
|
logger.info(`🚀 Console Server running on http://localhost:${PORT}`);
|
|
|
|
|
|
logger.info('✅ All backend services initialized successfully');
|
|
|
|
|
|
});
|
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
|
logger.error(`❌ Failed to start server: ${err.message}`);
|
|
|
|
|
|
process.exit(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
startServer();
|