ppob-backend/src/main.ts
2021-12-06 00:08:04 +07:00

45 lines
1.0 KiB
TypeScript

import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import { ValidationPipe, VersioningType} from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { Logger } from 'nestjs-pino';
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(),
{ bufferLogs: true },
);
const logger = app.get(Logger);
app.useLogger(logger);
app.enableCors();
app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
}),
);
app.enableVersioning({
type: VersioningType.URI,
});
const configService = app.get<ConfigService>(ConfigService);
const port = configService.get<number>('port');
await app.listen(port, '0.0.0.0', (error, address) => {
if (error) {
logger.error(error);
process.exit(1);
} else {
logger.log(`Server listening on ${address}`);
}
});
}
bootstrap();