TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/elysiajs/documentation/llms.txt
Use this file to discover all available pages before exploring further.
@elysia/cors plugin adds support for customizing Cross-Origin Resource Sharing behavior. It sets the appropriate Access-Control-* response headers and handles preflight OPTIONS requests automatically.
Installation
Basic usage
Access-Control-Allow-Origin: *.
Configuration
origin
Default: true
Controls which origins are permitted. Assigns the Access-Control-Allow-Origin header.
| Value type | Behavior |
|---|---|
true | Allow all origins (*) |
false | Block all cross-origin requests |
string | Allow only the exact origin string |
RegExp | Allow origins matching the pattern |
Function | Custom logic — return true to allow the request |
Array | Check each value in order; allow if any match |
methods
Default: '*'
Allowed HTTP methods for cross-origin requests. Assigns Access-Control-Allow-Methods.
'*'— allow all methodsstring— a single method or comma-delimited list, e.g.'GET, POST'string[]— array of methods, e.g.['GET', 'POST', 'PUT']null | ''— disallow cross-origin methods
allowedHeaders
Default: '*'
Headers the browser is permitted to send in a cross-origin request. Assigns Access-Control-Allow-Headers.
string— single header or comma-delimited list, e.g.'Content-Type, Authorization'string[]— array of headers, e.g.['Content-Type', 'Authorization']
exposeHeaders
Default: '*'
Headers that browsers are permitted to access in cross-origin responses. Assigns Access-Control-Expose-Headers.
string— single header or comma-delimited liststring[]— array of headers
credentials
Default: true
Whether the browser should expose the response to JavaScript when the request includes credentials (cookies, authorization headers, or TLS certificates). Assigns Access-Control-Allow-Credentials.
maxAge
Default: 5
How many seconds the results of a preflight request may be cached by the browser. Assigns Access-Control-Max-Age.
preflight
Whether the server should respond to preflight OPTIONS requests. The plugin sends the appropriate headers in response to requests that include Access-Control-Request-Method, Access-Control-Request-Headers, and Origin.
Patterns
Allow requests from a top-level domain
saltyaom.com.