think/packages/server/src/main.ts

36 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-02-20 11:51:55 +00:00
import { HttpResponseExceptionFilter } from '@exceptions/http-response.exception';
2022-05-22 12:40:55 +00:00
import { IS_PRODUCTION } from '@helpers/env.helper';
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';
2022-05-22 02:32:20 +00:00
import * as compression from 'compression';
2022-05-16 09:23:59 +00:00
import * as express from 'express';
import helmet from 'helmet';
2022-02-20 11:51:55 +00:00
import { AppModule } from './app.module';
2022-05-22 12:40:55 +00:00
import { AppClusterService } from './app-cluster.service';
2022-02-20 11:51:55 +00:00
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();
2022-05-22 02:32:20 +00:00
app.use(compression());
2022-02-20 11:51:55 +00:00
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
}
2022-05-22 12:40:55 +00:00
IS_PRODUCTION ? AppClusterService.clusterize(bootstrap) : bootstrap();