This plugin adds support for customizing Cross-Origin Resource Sharing behavior.
Install with:
Then use it:
This will set Elysia to accept requests from any origin.
Below is a config which is accepted by the plugin
@default true
Indicates whether the response can be shared with requesting code from the given origins.
Value can be one of the following:
*
(any origins)true
is returned.
true
.@default *
Allowed methods for cross origins requests.
Assign Access-Control-Allow-Methods header.
Value can be one of the following:
'GET, PUT, POST'
)['GET', 'PUT', 'POST']
@default *
Allowed headers for an incoming request.
Assign Access-Control-Allow-Headers header.
Value can be one of the following:
'Content-Type, Authorization'
.['Content-Type', 'Authorization']
@default *
Response CORS with specified headers.
Assign Access-Control-Expose-Headers header.
Value can be one of the following:
'Content-Type, X-Powered-By'
.['Content-Type', 'X-Powered-By']
@default true
The Access-Control-Allow-Credentials response header tells browsers whether to expose the response to the frontend JavaScript code when the request's credentials mode Request.credentials is include
.
When a request's credentials mode Request.credentials is include
, browsers will only expose the response to the frontend JavaScript code if the Access-Control-Allow-Credentials value is true.
Credentials are cookies, authorization headers, or TLS client certificates.
Assign Access-Control-Allow-Credentials header.
@default 5
Indicates how long the results of a preflight request (that is the information contained in the Access-Control-Allow-Methods and Access-Control-Allow-Headers headers) can be cached.
Assign Access-Control-Max-Age header.
The preflight request is a request sent to check if the CORS protocol is understood and if a server is aware of using specific methods and headers.
Response with OPTIONS request with 3 HTTP request headers:
This config indicates if the server should respond to preflight requests.
Below you can find the common patterns to use the plugin.
This will allows requests from top-level domains with `saltyaom.com'