2022-02-20 11:51:55 +00:00
|
|
|
import { HttpResponseExceptionFilter } from '@exceptions/http-response.exception';
|
2022-05-16 09:23:59 +00:00
|
|
|
import { ConfigService } from '@nestjs/config';
|
|
|
|
import { NestFactory } from '@nestjs/core';
|
2022-02-20 11:51:55 +00:00
|
|
|
import { ValidationPipe } from '@pipes/validation.pipe';
|
2022-05-16 09:23:59 +00:00
|
|
|
import { HttpResponseTransformInterceptor } from '@transforms/http-response.transform';
|
|
|
|
import * as express from 'express';
|
|
|
|
import helmet from 'helmet';
|
|
|
|
|
2022-02-20 11:51:55 +00:00
|
|
|
import { AppModule } from './app.module';
|
|
|
|
|
|
|
|
async function bootstrap() {
|
2022-05-21 06:39:56 +00:00
|
|
|
const app = await NestFactory.create(AppModule, {
|
|
|
|
logger: false,
|
|
|
|
});
|
2022-02-20 11:51:55 +00:00
|
|
|
const config = app.get(ConfigService);
|
2022-05-21 06:54:53 +00:00
|
|
|
const port = config.get('server.port') || 5002;
|
2022-02-20 11:51:55 +00:00
|
|
|
|
|
|
|
app.enableCors();
|
|
|
|
app.use(helmet());
|
|
|
|
app.use(express.json());
|
|
|
|
app.use(express.urlencoded({ extended: true }));
|
|
|
|
app.useGlobalFilters(new HttpResponseExceptionFilter());
|
|
|
|
app.useGlobalInterceptors(new HttpResponseTransformInterceptor());
|
|
|
|
app.useGlobalPipes(new ValidationPipe());
|
|
|
|
app.setGlobalPrefix(config.get('server.prefix') || '/');
|
2022-05-21 06:54:53 +00:00
|
|
|
|
|
|
|
await app.listen(port);
|
|
|
|
console.log(`[think] 主服务启动成功,端口:${port}`);
|
2022-02-20 11:51:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bootstrap();
|