import { app } from './app';
import { DomainBootstrap } from './core/runtime/DomainBootstrap';
import { logger } from './utils/logger';

const PORT = process.env.PORT || 3001;

async function startServer() {
  try {
    // 初始化领域模块
    logger.info('[Server] Initializing domain modules...');
    await DomainBootstrap.init();
    logger.info('[Server] Domain modules initialized successfully');
  } catch (error) {
    logger.error(`[Server] Error during domain initialization: ${(error as any).message}`);
    // 即使领域初始化失败，也继续启动服务器
    logger.warn('[Server] Continuing to start server despite domain initialization errors');
  }

  app.listen(PORT, () => {
    logger.info(`[Server] Running on port ${PORT}`);
  });
}

startServer();
