53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { AppModule } from './app.module';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
// 启用全局验证管道
|
|
app.useGlobalPipes(new ValidationPipe({
|
|
transform: true,
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
}));
|
|
|
|
// 启用 CORS
|
|
app.enableCors({
|
|
origin: process.env.FRONTEND_URL || true,
|
|
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
|
|
credentials: true,
|
|
});
|
|
|
|
// API 前缀
|
|
app.setGlobalPrefix('api');
|
|
|
|
// Swagger 文档配置
|
|
const config = new DocumentBuilder()
|
|
.setTitle('优艺家沙发翻新 API')
|
|
.setDescription('沙发翻新小程序后端API文档')
|
|
.setVersion('1.0')
|
|
.addBearerAuth()
|
|
.addTag('认证', '用户认证相关接口')
|
|
.addTag('用户管理', '用户管理相关接口')
|
|
.addTag('案例管理', '案例展示相关接口')
|
|
.addTag('服务管理', '服务项目相关接口')
|
|
.addTag('预约管理', '预约订单相关接口')
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('docs', app, document, {
|
|
swaggerOptions: {
|
|
persistAuthorization: true,
|
|
},
|
|
});
|
|
|
|
const port = process.env.PORT || 3000;
|
|
await app.listen(port);
|
|
|
|
console.log(`🚀 Application is running on: http://localhost:${port}`);
|
|
console.log(`📚 API Documentation: http://localhost:${port}/docs`);
|
|
}
|
|
bootstrap();
|