feat: ( cors ) update cors

This commit is contained in:
Abubeker Yasin
2026-07-14 11:16:58 +03:00
parent 68f9dd878d
commit 4cce471ebe
2 changed files with 11 additions and 7 deletions

View File

@@ -28,9 +28,8 @@ MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET=edr-dev
# CORS
FRONTEND_URL=http://localhost:5174
BACK_OFFICE_URL=http://localhost:5184
# CORS — comma-separated list of allowed origins (add more, comma-separated)
CORS_ORIGINS=http://localhost:5174,http://localhost:5184
# JWT (legacy passenger auth — being replaced by IAM)
# REQUIRED in production — use a random 32+ character string (e.g. openssl rand -hex 32)

View File

@@ -33,11 +33,16 @@ async function bootstrap() {
// version-neutral at their existing paths (e.g. /search, /bookings) — unchanged for the frontend.
app.enableVersioning({ type: VersioningType.URI });
// Allowed CORS origins come from a single comma-separated env var (CORS_ORIGINS),
// e.g. "https://portal.edr.et,https://backoffice.edr.et". Whitespace around each
// entry is trimmed and empties are dropped. Falls back to the local dev ports.
const corsOrigins = (process.env.CORS_ORIGINS ?? "http://localhost:5174,http://localhost:5184")
.split(",")
.map((origin) => origin.trim())
.filter((origin) => origin.length > 0);
app.enableCors({
origin: [
process.env.PORTAL_URL ?? "http://localhost:5174",
process.env.BACK_OFFICE_URL ?? "http://localhost:5184",
],
origin: corsOrigins,
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization', 'Accept-Language', 'X-Request-ID'],
credentials: true,