diff --git a/apps/api-gateway/src/main.ts b/apps/api-gateway/src/main.ts index 931ffac6..8d2e282a 100644 --- a/apps/api-gateway/src/main.ts +++ b/apps/api-gateway/src/main.ts @@ -1,64 +1,64 @@ -import fastifyCookie from '@fastify/cookie' -import fastifyMultipart from '@fastify/multipart' -import { Logger } from '@nestjs/common' -import { ConfigService } from '@nestjs/config' -import { NestFactory } from '@nestjs/core' -import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify' -import { AppModule } from './app/app.module' +import fastifyCookie from '@fastify/cookie'; +import fastifyMultipart from '@fastify/multipart'; +import { Logger } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { NestFactory } from '@nestjs/core'; +import { + FastifyAdapter, + NestFastifyApplication, +} from '@nestjs/platform-fastify'; +import { AppModule } from './app/app.module'; -const globalPrefix = '/api/v1' +const globalPrefix = '/api/v1'; async function bootstrap() { - const app = await NestFactory.create( - AppModule, - new FastifyAdapter({ - // logger: (process.env['LOG_LEVELS'].split(',') as LogLevel[]) ?? (['error', 'log', 'verbose', 'warn'] as LogLevel[]), - // logger: (process.env['LOG_LEVELS'].split(',') as LogLevel[]) ?? (['error', 'log', 'verbose', 'warn'] as LogLevel[]), - logger: { - // level: (process.env['LOG_LEVELS'].split(',') as LogLevel[]) ?? (['error', 'log', 'verbose', 'warn'] as LogLevel[]) - // level: [''] - level: 'error', - }, - }), - { - rawBody: true, - }, - ) + const app = await NestFactory.create( + AppModule, + new FastifyAdapter({ + // logger: (process.env['LOG_LEVELS'].split(',') as LogLevel[]) ?? (['error', 'log', 'verbose', 'warn'] as LogLevel[]), + // logger: (process.env['LOG_LEVELS'].split(',') as LogLevel[]) ?? (['error', 'log', 'verbose', 'warn'] as LogLevel[]), + logger: { + // level: (process.env['LOG_LEVELS'].split(',') as LogLevel[]) ?? (['error', 'log', 'verbose', 'warn'] as LogLevel[]) + // level: [''] + level: 'error', + }, + }), + { + rawBody: true, + } + ); - const configService = app.get(ConfigService) - // const frontendUrl = configService.get('FRONTEND_HOST') + const configService = app.get(ConfigService); + const frontendUrl = configService.get('FRONTEND_HOST'); - // app.enableCors({ - // origin: [frontendUrl], - // methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], - // credentials: true, - // }) + app.enableCors({ + origin: [frontendUrl], + methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], + credentials: true, + }); - app.enableCors({ - origin: '*', - methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'], - // credentials: true, - }) + await app.register(fastifyMultipart, { + attachFieldsToBody: 'keyValues', + // eslint-disable-next-line @typescript-eslint/no-explicit-any + async onFile(part: any) { + const buffer = await part.toBuffer(); + part.value = buffer; + }, + }); - await app.register(fastifyMultipart, { - attachFieldsToBody: 'keyValues', - // eslint-disable-next-line @typescript-eslint/no-explicit-any - async onFile(part: any) { - const buffer = await part.toBuffer() - part.value = buffer - }, - }) + await app.register(fastifyCookie, { + secret: configService.get('COOKIES_SIGNATURE'), + }); - await app.register(fastifyCookie, { - secret: configService.get('COOKIES_SIGNATURE'), - }) + app.setGlobalPrefix(globalPrefix); - app.setGlobalPrefix(globalPrefix) + const port = process.env.PORT_API_GATEWAY || 3001; + const host = process.env.ENV === 'prod' ? '0.0.0.0' : '127.0.0.1'; - const port = process.env.PORT_API_GATEWAY || 3001 - - await app.listen(port) - Logger.log(`🚀 Api service is running on: http://localhost:${port}${globalPrefix}`) + await app.listen(port, host); + Logger.log( + `🚀 Api service is running on: http://${host}:${port}${globalPrefix}` + ); } -bootstrap() +bootstrap();