import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import { FastifyAdapter, NestFastifyApplication, } from '@nestjs/platform-fastify'; import { NotFoundException, ValidationPipe } from '@nestjs/common'; import { TransformHttpResponseInterceptor } from './common/interceptors/http-response.interceptor'; import fastifyMultipart from '@fastify/multipart'; import { WsRedisIoAdapter } from './ws/adapter/ws-redis.adapter'; import { InternalLogFilter } from './common/logger/internal-log-filter'; import fastifyCookie from '@fastify/cookie'; async function bootstrap() { const app = await NestFactory.create( AppModule, new FastifyAdapter({ ignoreTrailingSlash: true, ignoreDuplicateSlashes: true, maxParamLength: 500, }), { logger: new InternalLogFilter(), }, ); app.setGlobalPrefix('api'); const redisIoAdapter = new WsRedisIoAdapter(app); await redisIoAdapter.connectToRedis(); app.useWebSocketAdapter(redisIoAdapter); await app.register(fastifyMultipart as any); await app.register(fastifyCookie as any); app .getHttpAdapter() .getInstance() .addHook('preHandler', function (req, reply, done) { if ( req.originalUrl.startsWith('/api') && !req.originalUrl.startsWith('/api/auth/setup') ) { if (!req.raw?.['workspaceId']) { throw new NotFoundException('Workspace not found'); } done(); } else { done(); } }); app.useGlobalPipes( new ValidationPipe({ whitelist: true, stopAtFirstError: true, transform: true, }), ); app.enableCors(); app.useGlobalInterceptors(new TransformHttpResponseInterceptor()); app.enableShutdownHooks(); await app.listen(process.env.PORT || 3000, '0.0.0.0'); } bootstrap();