A simple frock middleware to enable CORS.
npm install --save-dev frock-middleware-cors
You would use this middleware in your frockfile.json
as follows:
{
"servers": [
{
"port": 8080,
"routes": [
{
"path": "/cors-api",
"methods": ["GET"],
"handler": "frock-static",
"middleware": [
{
"handler": "frock-middleware-cors",
"options": {
"allowOrigin": "http://foo.com",
"allowCredentials": true
}
}
]
}
]
}
]
}
A string or an array of origin
s specifies URIs that may access the resource.
It defaults to *
.
options: {
allowOrigin: ['http://foo.com', 'http://bar.com']
}
A string or an array of methods which are allowed to access the resource.
It defaults to ['GET', 'POST', 'OPTIONS', 'PUT', 'PATCH', 'DELETE', 'CONNECT']
.
options: {
allowMethods: 'GET'
}
A string or an array of headers that are used in response to a preflight request to indicate which HTTP headers can be used when the actual request is made.
It defaults to ['X-Requested-With', 'X-HTTP-Method-Override', 'Content-Type', 'Accept']
.
options: {
allowHeaders: 'Content-Type'
}
Indicates whether or nor the response to the request can be exposed when the crenditials
flag is true.
It defaults to false
.
options: {
allowCredentials: true
}
Indicates how long the results of a preflight request can be cached.
It defaults to 86400
.
options: {
maxAge: '86400'
}