feat(backoffice): add CORS_ORIGINS env var support
This commit is contained in:
parent
dfdb8bc943
commit
ae7003d3fa
3 changed files with 7 additions and 7 deletions
|
|
@ -27,10 +27,7 @@ BACKEND_HOST=localhost:8521
|
||||||
ENV=development
|
ENV=development
|
||||||
|
|
||||||
# CORS Origins (comma-separated)
|
# CORS Origins (comma-separated)
|
||||||
# Development:
|
CORS_ORIGINS=http://localhost:3000,http://localhost:8963
|
||||||
# CORS_ORIGINS=http://localhost:3000,http://localhost:8963
|
|
||||||
# Production:
|
|
||||||
CORS_ORIGINS=https://gohorsejobs.com,https://gohorsejobs-dev.appwrite.network,https://api-dev2.gohorsejobs.com
|
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Cloudflare API (for cache management)
|
# Cloudflare API (for cache management)
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,9 @@ BACKOFFICE_PORT=3001
|
||||||
BACKOFFICE_HOST=0.0.0.0
|
BACKOFFICE_HOST=0.0.0.0
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
|
|
||||||
|
# CORS Origins (comma-separated)
|
||||||
|
CORS_ORIGINS=https://gohorsejobs.com,https://gohorsejobs-dev.appwrite.network,https://api-dev2.gohorsejobs.com
|
||||||
|
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
# Stripe
|
# Stripe
|
||||||
# =============================================================================
|
# =============================================================================
|
||||||
|
|
|
||||||
|
|
@ -38,12 +38,12 @@ async function bootstrap() {
|
||||||
// CORS configuration (Fastify-native)
|
// CORS configuration (Fastify-native)
|
||||||
app.enableCors({
|
app.enableCors({
|
||||||
origin: (origin, callback) => {
|
origin: (origin, callback) => {
|
||||||
|
// Parse CORS_ORIGINS from env (comma-separated)
|
||||||
|
const envOrigins = process.env.CORS_ORIGINS?.split(',').map(o => o.trim()) || [];
|
||||||
const allowedOrigins = [
|
const allowedOrigins = [
|
||||||
'http://localhost:3000',
|
'http://localhost:3000',
|
||||||
'http://localhost:8963',
|
'http://localhost:8963',
|
||||||
'https://gohorsejobs.com',
|
...envOrigins,
|
||||||
'https://admin.gohorsejobs.com',
|
|
||||||
process.env.FRONTEND_URL,
|
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
|
|
||||||
if (!origin || allowedOrigins.includes(origin)) {
|
if (!origin || allowedOrigins.includes(origin)) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue