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:

  1. Manually add each port to DEFAULT_CORS_ORIGINS
  2. Use wildcard pattern matching
  3. Allow all localhost origins automatically
  4. 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


🔗 Related


Auto-generated by MCP Smart Consolidation