Evo.Auth/apps/api/src/main.ts
2023-11-02 11:38:49 +03:00

50 lines
1.4 KiB
TypeScript

/* eslint-disable import/no-duplicates */
/* eslint-disable unicorn/prefer-top-level-await */
import { AppModule } from './app.module';
import { env } from './config/env';
import { fastifyCookie } from '@fastify/cookie';
import proxy from '@fastify/http-proxy';
import type { INestApplication } from '@nestjs/common';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import type { NestFastifyApplication } from '@nestjs/platform-fastify';
import { FastifyAdapter } from '@nestjs/platform-fastify';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
function setupOpenApi(app: INestApplication) {
const config = new DocumentBuilder()
.setTitle('Evo.Auth')
.setVersion('1.0')
// .addTag('api')
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('swagger', app, document, { useGlobalPrefix: true });
}
async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter({
logger: true,
})
);
await app.register(fastifyCookie, {
secret: env.API_SECRET,
});
await app.register(proxy, {
http2: false,
httpMethods: ['GET'],
upstream: `http://${env.WEB_SERVER}`,
});
app.useGlobalPipes(new ValidationPipe({ stopAtFirstError: true }));
setupOpenApi(app);
await app.listen(env.API_PORT, '0.0.0.0');
}
bootstrap();