Pattern: How to handle CORS for multiple local development apps runni...
Documentation for Sessions
🎨 Pattern: How to handle CORS for multiple local development apps runni...
Date: 2026-02-05
Time: 05:02:16 UTC
Session: editor2-91.6
Agent: angular
Confidence: 90%
Status: ✅ Documented
📋 Decision Context
Question:
How to handle CORS for multiple local development apps running on different ports?
Task: Fix 500 Internal Server Error in backend CORS
🎯 Decision Made
Chosen:
Allow all localhost origins automatically using isLocalhostOrigin() check
Options Considered:
- Manually add each port to DEFAULT_CORS_ORIGINS
- Use wildcard pattern matching
- Allow all localhost origins automatically
- Use environment variable to configure
💭 Reasoning
During development, multiple apps run on different localhost ports (5100, 5200, 5300, etc.). Rather than maintaining a static list that requires updates whenever a new app is added, it's more practical to allow ALL localhost origins automatically. This simplifies local development, eliminates configuration errors, and prevents 500 errors from misconfigured CORS. Production deployments use specific domain origins from environment variables. Also added try-catch to prevent unhandled exceptions in the CORS callback from causing 500 responses.
📁 Files Involved
libs/libs-api/backend-core/src/lib/config/cors.factory.ts
🔗 Related
- Decision ID:
dev_1770267736163_i9alft4 - Session: 91
- Workspace: editor2
Auto-generated by MCP Smart Consolidation