feat: 优化项目目录结构
This commit is contained in:
31
apps/backend/src/main.ts
Normal file
31
apps/backend/src/main.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { AppModule } from './app.module';
|
||||
import { BadRequestException, ValidationPipe } from '@nestjs/common';
|
||||
import { ResponseInterceptor } from './common/interceptors/response.interceptor';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
whitelist: true,
|
||||
forbidNonWhitelisted: true,
|
||||
stopAtFirstError: true,
|
||||
exceptionFactory: (errors) => {
|
||||
const error = errors[0];
|
||||
const firstConstraint = error.constraints
|
||||
? Object.values(error.constraints)[0]
|
||||
: '验证失败';
|
||||
|
||||
throw new BadRequestException({
|
||||
message: firstConstraint,
|
||||
error: 'Bad Request',
|
||||
statusCode: 400,
|
||||
});
|
||||
},
|
||||
}),
|
||||
);
|
||||
app.useGlobalInterceptors(new ResponseInterceptor());
|
||||
await app.listen(process.env.PORT ?? 3001);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in New Issue
Block a user