Summary: - Implement DC module Portal page with 3 tool cards - Create ToolCard component with decorative background and hover animations - Implement TaskList component with table layout and progress bars - Implement AssetLibrary component with tab switching and file cards - Complete database verification (4 tables confirmed) - Complete backend API verification (6 endpoints ready) - Optimize UI to match prototype design (V2.html) Frontend Components (~715 lines): - components/ToolCard.tsx - Tool cards with animations - components/TaskList.tsx - Recent tasks table view - components/AssetLibrary.tsx - Data asset library with tabs - hooks/useRecentTasks.ts - Task state management - hooks/useAssets.ts - Asset state management - pages/Portal.tsx - Main portal page - types/portal.ts - TypeScript type definitions Backend Verification: - Backend API: 1495 lines code verified - Database: dc_schema with 4 tables verified - API endpoints: 6 endpoints tested (templates API works) Documentation: - Database verification report - Backend API test report - Phase 1 completion summary - UI optimization report - Development task checklist - Development plan for Tool B Status: Phase 1 completed (100%), ready for browser testing Next: Phase 2 - Tool B Step 1 and 2 development
159 lines
5.3 KiB
TypeScript
159 lines
5.3 KiB
TypeScript
import Fastify from 'fastify';
|
||
import cors from '@fastify/cors';
|
||
import multipart from '@fastify/multipart';
|
||
import { config, validateEnv } from './config/env.js';
|
||
import { testDatabaseConnection, prisma } from './config/database.js';
|
||
import { projectRoutes } from './legacy/routes/projects.js';
|
||
import { agentRoutes } from './legacy/routes/agents.js';
|
||
import { conversationRoutes } from './legacy/routes/conversations.js';
|
||
import knowledgeBaseRoutes from './legacy/routes/knowledgeBases.js';
|
||
import { chatRoutes } from './legacy/routes/chatRoutes.js';
|
||
import { batchRoutes } from './legacy/routes/batchRoutes.js';
|
||
import reviewRoutes from './legacy/routes/reviewRoutes.js';
|
||
import { aslRoutes } from './modules/asl/routes/index.js';
|
||
import { registerDCRoutes, initDCModule } from './modules/dc/index.js';
|
||
import { registerHealthRoutes } from './common/health/index.js';
|
||
import { logger } from './common/logging/index.js';
|
||
import { registerTestRoutes } from './test-platform-api.js';
|
||
|
||
|
||
// 全局处理BigInt序列化
|
||
(BigInt.prototype as any).toJSON = function() {
|
||
return Number(this);
|
||
};
|
||
|
||
const fastify = Fastify({
|
||
logger: {
|
||
level: config.logLevel,
|
||
transport: {
|
||
target: 'pino-pretty',
|
||
options: {
|
||
colorize: true,
|
||
translateTime: 'HH:MM:ss Z',
|
||
ignore: 'pid,hostname',
|
||
},
|
||
},
|
||
},
|
||
});
|
||
|
||
// 注册CORS插件 - 完整配置
|
||
await fastify.register(cors, {
|
||
origin: true, // 开发环境允许所有来源
|
||
credentials: true,
|
||
methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'OPTIONS', 'HEAD'], // 明确允许的HTTP方法
|
||
allowedHeaders: ['Content-Type', 'Authorization', 'X-Requested-With', 'Accept', 'Origin'], // 允许的请求头
|
||
exposedHeaders: ['Content-Range', 'X-Content-Range'], // 暴露的响应头
|
||
maxAge: 600, // preflight请求缓存时间(秒)
|
||
preflightContinue: false, // Fastify处理preflight请求
|
||
});
|
||
console.log('✅ CORS已配置: 允许所有HTTP方法 (GET, POST, PUT, DELETE, PATCH, OPTIONS)');
|
||
|
||
// 注册文件上传插件
|
||
await fastify.register(multipart, {
|
||
limits: {
|
||
fileSize: 10 * 1024 * 1024, // 10MB
|
||
},
|
||
});
|
||
console.log('✅ 文件上传插件已配置: 最大文件大小 10MB');
|
||
|
||
|
||
// ============================================
|
||
// 【平台基础设施】健康检查路由
|
||
// ============================================
|
||
// 注册健康检查路由(/health, /health/liveness, /health/readiness)
|
||
await registerHealthRoutes(fastify);
|
||
logger.info('✅ 健康检查路由已注册');
|
||
|
||
// ============================================
|
||
// 【临时】平台基础设施测试API
|
||
// ============================================
|
||
await registerTestRoutes(fastify);
|
||
logger.info('✅ 测试API已注册: /test/platform');
|
||
|
||
// API路由前缀
|
||
fastify.get('/api/v1', async () => {
|
||
return {
|
||
message: 'AI Clinical Research Platform API',
|
||
version: '1.0.0',
|
||
environment: config.nodeEnv,
|
||
};
|
||
});
|
||
|
||
// 注册项目管理路由
|
||
await fastify.register(projectRoutes, { prefix: '/api/v1' });
|
||
|
||
// 注册智能体管理路由
|
||
await fastify.register(agentRoutes, { prefix: '/api/v1' });
|
||
|
||
// 注册对话管理路由
|
||
await fastify.register(conversationRoutes, { prefix: '/api/v1' });
|
||
|
||
// 注册知识库管理路由
|
||
await fastify.register(knowledgeBaseRoutes, { prefix: '/api/v1' });
|
||
|
||
// 注册通用对话路由
|
||
await fastify.register(chatRoutes, { prefix: '/api/v1' });
|
||
|
||
// Phase 3: 注册批处理路由
|
||
await fastify.register(batchRoutes, { prefix: '/api/v1' });
|
||
|
||
// 注册稿件审查路由
|
||
await fastify.register(reviewRoutes, { prefix: '/api/v1' });
|
||
|
||
// ============================================
|
||
// 【业务模块】ASL - AI智能文献筛选
|
||
// ============================================
|
||
await fastify.register(aslRoutes, { prefix: '/api/v1/asl' });
|
||
logger.info('✅ ASL智能文献筛选路由已注册: /api/v1/asl');
|
||
|
||
// ============================================
|
||
// 【业务模块】DC - 数据清洗整理
|
||
// ============================================
|
||
await registerDCRoutes(fastify);
|
||
logger.info('✅ DC数据清洗模块路由已注册: /api/v1/dc/tool-b');
|
||
|
||
// 启动服务器
|
||
const start = async () => {
|
||
try {
|
||
// 验证环境变量
|
||
validateEnv();
|
||
|
||
// 测试数据库连接
|
||
console.log('🔍 正在测试数据库连接...');
|
||
const dbConnected = await testDatabaseConnection();
|
||
|
||
if (!dbConnected) {
|
||
console.error('❌ 数据库连接失败,无法启动服务器');
|
||
process.exit(1);
|
||
}
|
||
|
||
// 初始化DC模块(Seed预设模板)
|
||
try {
|
||
await initDCModule();
|
||
logger.info('✅ DC模块初始化成功');
|
||
} catch (error) {
|
||
logger.warn('⚠️ DC模块初始化失败,但不影响启动', { error });
|
||
}
|
||
|
||
// 启动Fastify服务器
|
||
await fastify.listen({
|
||
port: config.port,
|
||
host: config.host,
|
||
});
|
||
|
||
console.log('\n' + '='.repeat(60));
|
||
console.log('🚀 AI临床研究平台 - 后端服务器启动成功!');
|
||
console.log('='.repeat(60));
|
||
console.log(`📍 服务地址: http://${config.host === '0.0.0.0' ? 'localhost' : config.host}:${config.port}`);
|
||
console.log(`🔍 健康检查: http://localhost:${config.port}/health`);
|
||
console.log(`📡 API入口: http://localhost:${config.port}/api/v1`);
|
||
console.log(`🌍 运行环境: ${config.nodeEnv}`);
|
||
console.log('='.repeat(60) + '\n');
|
||
} catch (err) {
|
||
fastify.log.error(err);
|
||
process.exit(1);
|
||
}
|
||
};
|
||
|
||
start();
|