Skip to content

Commit

Permalink
configure CORS_ORIGIN with dev and local values
Browse files Browse the repository at this point in the history
  • Loading branch information
jragunanthan committed Oct 24, 2024
1 parent 342a2a3 commit 850e551
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
bootstrap();

0 comments on commit 850e551

Please sign in to comment.