From 850e5517703aeb2ea76cc22110aa6d016c86ec66 Mon Sep 17 00:00:00 2001 From: jragunanthan Date: Fri, 25 Oct 2024 01:10:13 +0530 Subject: [PATCH] configure CORS_ORIGIN with dev and local values --- backend/src/main.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/backend/src/main.ts b/backend/src/main.ts index d164076..028f529 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -14,20 +14,27 @@ // limitations under the License.  //  +import * as dotenv from 'dotenv'; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; -import * as dotenv from 'dotenv'; import * as cors from 'cors'; import * as cookieParser from 'cookie-parser'; +dotenv.config(); + async function bootstrap() { - dotenv.config(); const app = await NestFactory.create(AppModule); + + // Split CORS_ORIGIN values by comma to handle multiple origins + const allowedOrigins = process.env.CORS_ORIGIN?.split(',') || []; + + // Using NestJS built-in CORS support with multiple origins from CORS_ORIGIN env app.use(cors({ - origin: [process.env.FLEET_MANAGER_BACKEND_URL, process.env.IFRIC_PLATFORM_BACKEND_URL, process.env.IFRIC_REGISTRY_BACKEND_URL, process.env.IFX_PLATFORM_BACKEND_URL], + origin: allowedOrigins, credentials: true, })); + app.use(cookieParser()); await app.listen(4010); } -bootstrap(); \ No newline at end of file +bootstrap();