feat(backoffice): add CORS_ORIGINS env var support

This commit is contained in:
Tiago Yamamoto 2025-12-24 00:03:52 -03:00
parent dfdb8bc943
commit ae7003d3fa
3 changed files with 7 additions and 7 deletions

View file

@ -27,10 +27,7 @@ BACKEND_HOST=localhost:8521
ENV=development
# CORS Origins (comma-separated)
# Development:
# CORS_ORIGINS=http://localhost:3000,http://localhost:8963
# Production:
CORS_ORIGINS=https://gohorsejobs.com,https://gohorsejobs-dev.appwrite.network,https://api-dev2.gohorsejobs.com
CORS_ORIGINS=http://localhost:3000,http://localhost:8963
# =============================================================================
# Cloudflare API (for cache management)

View file

@ -7,6 +7,9 @@ BACKOFFICE_PORT=3001
BACKOFFICE_HOST=0.0.0.0
NODE_ENV=development
# CORS Origins (comma-separated)
CORS_ORIGINS=https://gohorsejobs.com,https://gohorsejobs-dev.appwrite.network,https://api-dev2.gohorsejobs.com
# =============================================================================
# Stripe
# =============================================================================

View file

@ -38,12 +38,12 @@ async function bootstrap() {
// CORS configuration (Fastify-native)
app.enableCors({
origin: (origin, callback) => {
// Parse CORS_ORIGINS from env (comma-separated)
const envOrigins = process.env.CORS_ORIGINS?.split(',').map(o => o.trim()) || [];
const allowedOrigins = [
'http://localhost:3000',
'http://localhost:8963',
'https://gohorsejobs.com',
'https://admin.gohorsejobs.com',
process.env.FRONTEND_URL,
...envOrigins,
].filter(Boolean);
if (!origin || allowedOrigins.includes(origin)) {