46 lines
1.3 KiB
TypeScript
46 lines
1.3 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { ValidationPipe } from '@nestjs/common';
|
|
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
|
import { AppModule } from './app.module';
|
|
import { HttpExceptionFilter } from './common/filters/http-exception.filter';
|
|
|
|
async function bootstrap() {
|
|
const app = await NestFactory.create(AppModule);
|
|
|
|
// 设置全局前缀
|
|
app.setGlobalPrefix('api');
|
|
|
|
// 启用 CORS (支持微信小游戏)
|
|
app.enableCors({
|
|
origin: true,
|
|
credentials: true,
|
|
});
|
|
|
|
// 全局验证管道
|
|
app.useGlobalPipes(
|
|
new ValidationPipe({
|
|
whitelist: true,
|
|
forbidNonWhitelisted: true,
|
|
transform: true,
|
|
}),
|
|
);
|
|
|
|
// 全局异常过滤器
|
|
app.useGlobalFilters(new HttpExceptionFilter());
|
|
|
|
// Swagger 文档配置
|
|
const config = new DocumentBuilder()
|
|
.setTitle('MemeMind Server API')
|
|
.setDescription('微信小游戏 MemeMind 服务端 API 文档')
|
|
.setVersion('1.0')
|
|
.build();
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
SwaggerModule.setup('api/docs', app, document);
|
|
|
|
const port = process.env.PORT ?? 3000;
|
|
await app.listen(port);
|
|
console.log(`Application is running on: http://localhost:${port}/api`);
|
|
console.log(`Swagger documentation: http://localhost:${port}/api/docs`);
|
|
}
|
|
bootstrap();
|