think/packages/server/src/main.ts

27 lines
1019 B
TypeScript
Raw Normal View History

2022-02-20 11:51:55 +00:00
import * as express from 'express';
import helmet from 'helmet';
import { NestFactory } from '@nestjs/core';
import { ConfigService } from '@nestjs/config';
import { HttpResponseExceptionFilter } from '@exceptions/http-response.exception';
import { HttpResponseTransformInterceptor } from '@transforms/http-response.transform';
import { ValidationPipe } from '@pipes/validation.pipe';
import { AppModule } from './app.module';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const config = app.get(ConfigService);
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') || '/');
await app.listen(config.get('server.port') || 4000);
2022-04-25 01:19:48 +00:00
console.log('[think] 主服务启动成功');
2022-02-20 11:51:55 +00:00
}
bootstrap();