Skip to content

Commit

Permalink
ci(fastify): fix listening host
Browse files Browse the repository at this point in the history
  • Loading branch information
anteqkois committed May 9, 2024
1 parent 548fa52 commit 823182e
Showing 1 changed file with 52 additions and 52 deletions.
104 changes: 52 additions & 52 deletions apps/api-gateway/src/main.ts
Original file line number Diff line number Diff line change
@@ -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<NestFastifyApplication>(
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<NestFastifyApplication>(
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();

0 comments on commit 823182e

Please sign in to comment.