fix: Make CORS origins configurable via environment variable
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
Add CORS_ORIGINS environment variable to allow configuring allowed origins in production. Defaults to the Traefik domain.
This commit is contained in:
+3
-4
@@ -56,10 +56,9 @@ const corsOptions = {
|
|||||||
// Allow requests with no origin (mobile apps, Postman, etc)
|
// Allow requests with no origin (mobile apps, Postman, etc)
|
||||||
if (!origin) return callback(null, true);
|
if (!origin) return callback(null, true);
|
||||||
|
|
||||||
// In production, you might want to whitelist specific origins
|
// In production, check against configured allowed origins
|
||||||
if (config.app.env === 'production') {
|
if (config.app.env === 'production' && config.cors.origins.length > 0) {
|
||||||
const allowedOrigins = ['https://your-domain.com'];
|
if (config.cors.origins.indexOf(origin) === -1) {
|
||||||
if (allowedOrigins.indexOf(origin) === -1) {
|
|
||||||
return callback(new Error('Not allowed by CORS'));
|
return callback(new Error('Not allowed by CORS'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,9 @@ const config = {
|
|||||||
port: parseInt(process.env.REDIS_PORT || '6379', 10),
|
port: parseInt(process.env.REDIS_PORT || '6379', 10),
|
||||||
password: process.env.REDIS_PASSWORD,
|
password: process.env.REDIS_PASSWORD,
|
||||||
},
|
},
|
||||||
|
cors: {
|
||||||
|
origins: process.env.CORS_ORIGINS ? process.env.CORS_ORIGINS.split(',').map(o => o.trim()) : [],
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Validate required configuration
|
// Validate required configuration
|
||||||
|
|||||||
@@ -42,6 +42,8 @@ services:
|
|||||||
- REPORT_SENDER=${REPORT_SENDER:-}
|
- REPORT_SENDER=${REPORT_SENDER:-}
|
||||||
- REPORT_RECIPIENT=${REPORT_RECIPIENT:-}
|
- REPORT_RECIPIENT=${REPORT_RECIPIENT:-}
|
||||||
- REPORT_SCHEDULE=${REPORT_SCHEDULE:-0 0 * * 1}
|
- REPORT_SCHEDULE=${REPORT_SCHEDULE:-0 0 * * 1}
|
||||||
|
# CORS configuration
|
||||||
|
- CORS_ORIGINS=${CORS_ORIGINS:-https://minio-webui.local.nothaft.cloud}
|
||||||
volumes:
|
volumes:
|
||||||
- /mnt/DockerMount/minio-webui/logs:/app/logs
|
- /mnt/DockerMount/minio-webui/logs:/app/logs
|
||||||
- /mnt/DockerMount/minio-webui/mc-config:/home/nodejs/.mc
|
- /mnt/DockerMount/minio-webui/mc-config:/home/nodejs/.mc
|
||||||
|
|||||||
Reference in New Issue
Block a user