Skip to content

feat(api): configure CORS origins from environment variable (FRO-61)#34

Merged
pierrick-fonquerne merged 3 commits intodevelopfrom
fix/deployment
Jan 19, 2026
Merged

feat(api): configure CORS origins from environment variable (FRO-61)#34
pierrick-fonquerne merged 3 commits intodevelopfrom
fix/deployment

Conversation

@pierrick-fonquerne
Copy link
Copy Markdown
Owner

🎯 Objectif

Permettre au frontend Vercel de communiquer avec le backend Railway en configurant CORS via variable d'environnement.

📋 Changements

Program.cs (lignes 23-36)

// Avant
policy.WithOrigins("http://localhost:5173")

// Après
var corsOrigins = builder.Configuration["CorsOrigins"]?.Split(',')
    ?? new[] { "http://localhost:5173" };
policy.WithOrigins(corsOrigins)

✅ Avantages

  • Local : Utilise http://localhost:5173 par défaut (pas de config nécessaire)
  • Staging Railway : Lit la variable CorsOrigins déjà configurée sur Railway
    • https://staging.fantasy-realm.com,https://*.vercel.app
  • Flexible : Supporte plusieurs origins séparés par virgule

🧪 Tests

  • ✅ Build : 0 warnings, 0 errors
  • ✅ Tests unitaires : 113 passed
  • ✅ Tests intégration : 44 passed

🚀 Impact

Une fois mergé, Railway redéploiera automatiquement avec la nouvelle configuration CORS. Le frontend Vercel pourra alors appeler l'API Railway sans erreur "Impossible de contacter le serveur".

📝 Ticket Jira

FRO-61: Déploiement infrastructure recette (Railway + MongoDB Atlas)

- Read CorsOrigins from configuration/environment variable
- Support multiple origins separated by comma
- Fallback to localhost:5173 for local development
- Allows Vercel frontend to connect to Railway backend

Build: ✓ (0 warnings, 0 errors)
Tests: ✓ (157 passed - 113 unit + 44 integration)
@vercel
Copy link
Copy Markdown

vercel bot commented Jan 19, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
fantasyrealm-character-manager Ready Ready Preview, Comment Jan 19, 2026 1:24pm

- Add .env.staging with Railway staging API URL
- Add .env.production placeholder for future production environment
- Add build:staging script to use staging configuration
- Allow .env.staging and .env.production in git (no secrets, only public URLs)
- Simplify api.ts to rely on environment files

Environment configuration:
- Development: localhost:5000/api (fallback)
- Staging: https://fantasyrealm-api-staging.up.railway.app/api
- Production: To be configured with Railway production URL

Build: ✓ (staging mode verified)
@pierrick-fonquerne pierrick-fonquerne merged commit db31f47 into develop Jan 19, 2026
6 checks passed
@pierrick-fonquerne pierrick-fonquerne deleted the fix/deployment branch January 19, 2026 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant