CORS Configuration
Secure cross-origin requests made simple. Enable CORS with one line, configure origins, and protect your API automatically.
On this page
CORS That Just Works
Enable CORS with one line. Configure origins automatically.
Secure by default, flexible when needed.
It's This Simple
Enable CORS with one line
typescript
Why CORS Matters
Without CORS, browsers block cross-origin requests. With CORS, you control which origins can access your API securely.
Traditional CORS setup requires manual header management and preflight handling. We handle that automatically.
Without CORS
- •Browsers block cross-origin requests
- •Manual header management
- •Complex preflight handling
- •Security configuration errors
With MoroJS
- •One-line CORS enablement
- •Automatic preflight handling
- •Secure defaults
- •Flexible configuration
It's This Easy
Configure allowed origins, methods, and headers. That's it.
Configure allowed origins
typescript
Why It Makes Sense
Secure
Control which origins can access your API. Secure by default.
Automatic
Preflight requests handled automatically. No manual header management.
Flexible
Configure per-route or globally. Environment-specific settings.
How It Works
MoroJS automatically handles CORS preflight requests, validates origins against your allowed list, and sets appropriate headers. When CORS is enabled, all routes automatically support cross-origin requests according to your configuration.
Configuration
Simple CORS Configuration
typescript
Configure Allowed Origins
typescript
Environment-Specific Configuration
typescript
Advanced Configuration
For advanced use cases, you can configure dynamic origin validation, per-route CORS settings, and database-driven origin management.
Dynamic Origin Validation
typescript
Route-Specific CORS
typescript