Skip to content

Commit

Permalink
Merge pull request #32 from IndustryFusion/one-cors-env
Browse files Browse the repository at this point in the history
configure CORS_ORIGIN with dev and local values
  • Loading branch information
LahariMIBS authored Oct 25, 2024
2 parents 342a2a3 + 850e551 commit 9f00e8b
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 9f00e8b

Please sign in to comment.