import { NestFactory } from '@nestjs/core'; import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); app.enableCors({ origin: ['https://longde.cloud', 'http://localhost:4321'], methods: ['GET', 'POST', 'PUT', 'DELETE', 'PATCH'], credentials: true, }); const config = new DocumentBuilder() .setTitle('知习 API') .setDescription('知习 AI-first 系统化学习产品后端 API(v0.1)') .setVersion('0.1.0') .addTag('health', '服务健康检查') .addTag('auth', '用户认证') .addTag('users', '用户管理') .addTag('knowledge-base', '知识库') .addTag('knowledge-items', '知识点') .addTag('document-import', '资料导入') .addTag('learning-session', '学习会话') .addTag('active-recall', '主动回忆') .addTag('ai-analysis', 'AI 分析') .addTag('review', '复习管理') .addTag('focus-items', '待巩固项') .addTag('learning-activity', '学习活跃') .addTag('notifications', '消息通知') .addTag('feedback', '用户反馈') .addTag('waitlist', '等待名单') .build(); const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup('api-docs', app, document, { swaggerOptions: { persistAuthorization: true }, customCss: '.swagger-ui .topbar { display: none }', customSiteTitle: '知习 API 文档', }); app.getHttpAdapter().get('/api-docs-json', (_req: any, res: any) => { res.json(document); }); const port = process.env.PORT ?? 3000; await app.listen(port); console.log(`[API] Server running on http://localhost:${port}`); console.log(`[API] Swagger docs at http://localhost:${port}/api-docs`); } bootstrap();