Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/backend/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ REDIS_PORT=6379
# ── Frontend URL (for CORS and OAuth redirects) ─────────────────────────────
FRONTEND_URL=http://localhost:3000

# ── CORS ─────────────────────────────────────────────────────────────────────
# Comma-separated list of allowed origins. credentials are only passed for listed origins.
ALLOWED_ORIGINS=http://localhost:3000

# ── JWT / Auth ───────────────────────────────────────────────────────────────
JWT_SECRET=change-me-to-a-random-secret
REFRESH_TOKEN_SECRET=change-me-to-another-random-secret
Expand Down
19 changes: 19 additions & 0 deletions app/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ async function bootstrap() {
const app = await NestFactory.create(AppModule);
configureAppSecurity(app);

// Configure CORS with env-driven allowed origins
const allowedOrigins = (process.env.ALLOWED_ORIGINS ?? '')
.split(',')
.map((o) => o.trim())
.filter(Boolean);

app.enableCors({
origin: (origin, callback) => {
// Allow requests with no origin (e.g. server-to-server, curl)
if (!origin) return callback(null, true);
if (allowedOrigins.includes(origin)) {
return callback(null, true);
}
return callback(null, false);
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'],
});

// app.enableVersioning({...});

setupOpenApiDocs(app);
Expand Down
Loading