fix: Use CORS_ORIGIN env var in allowed origins list
- Add corsOrigin from config to allowedOrigins array - Log warning when CORS blocks an origin (helps debugging)
This commit is contained in:
@@ -27,17 +27,19 @@ async function bootstrap(): Promise<void> {
|
|||||||
app.use(helmet());
|
app.use(helmet());
|
||||||
app.use(compression());
|
app.use(compression());
|
||||||
|
|
||||||
// CORS configuration - Allow multiple origins for local development
|
// CORS configuration - Allow configured origin plus local development origins
|
||||||
const allowedOrigins = [
|
const allowedOrigins = [
|
||||||
|
corsOrigin,
|
||||||
'http://localhost:4200',
|
'http://localhost:4200',
|
||||||
'http://localhost:3000',
|
'http://localhost:3000',
|
||||||
'http://localhost:8080',
|
'http://localhost:8080',
|
||||||
];
|
].filter(Boolean);
|
||||||
app.enableCors({
|
app.enableCors({
|
||||||
origin: (origin, callback) => {
|
origin: (origin, callback) => {
|
||||||
if (!origin || allowedOrigins.includes(origin)) {
|
if (!origin || allowedOrigins.includes(origin)) {
|
||||||
callback(null, true);
|
callback(null, true);
|
||||||
} else {
|
} else {
|
||||||
|
logger.warn(`CORS blocked origin: ${origin}. Allowed: ${allowedOrigins.join(', ')}`);
|
||||||
callback(null, false);
|
callback(null, false);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user