diff --git a/src/main.ts b/src/main.ts index b629495..89383d8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,30 @@ async function bootstrap() { const app = await NestFactory.create(AppModule); const reflector = app.get(Reflector); + const allowedOrigins = [ + 'https://app.clipperia.com.br', + 'http://localhost:5173', + ]; + + app.enableCors({ + origin: ( + origin: string | undefined, + callback: (err: Error | null, allow?: boolean) => void, + ) => { + if (!origin) { + return callback(null, true); + } + + if (allowedOrigins.includes(origin)) { + return callback(null, true); + } + + return callback(new Error('CORS')); + }, + methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS', + credentials: true, + }); + app.useGlobalInterceptors(new ClassSerializerInterceptor(reflector)); await app.listen(process.env.PORT ?? 3000);