ocr-document-backend/src/main.ts
Hasta Ragil Saputra f83aaec778 feat: add cors
2021-11-27 20:12:43 +07:00

42 lines
972 B
TypeScript

import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import { AppModule } from './app.module';
import { ValidationPipe } 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,
}),
);
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();