2026-05-04 16:09:01 +08:00
|
|
|
|
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,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-09 18:25:04 +08:00
|
|
|
|
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 文档',
|
|
|
|
|
|
});
|
2026-05-04 16:09:01 +08:00
|
|
|
|
|
2026-05-09 18:25:04 +08:00
|
|
|
|
app.getHttpAdapter().get('/api-docs-json', (_req: any, res: any) => {
|
|
|
|
|
|
res.json(document);
|
|
|
|
|
|
});
|
2026-05-04 16:09:01 +08:00
|
|
|
|
|
|
|
|
|
|
const port = process.env.PORT ?? 3000;
|
|
|
|
|
|
await app.listen(port);
|
|
|
|
|
|
console.log(`[API] Server running on http://localhost:${port}`);
|
2026-05-09 18:25:04 +08:00
|
|
|
|
console.log(`[API] Swagger docs at http://localhost:${port}/api-docs`);
|
2026-05-04 16:09:01 +08:00
|
|
|
|
}
|
2026-05-09 18:25:04 +08:00
|
|
|
|
bootstrap();
|