Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dorayx/frock-middleware-cors
A simple CORS middleware for frock.
https://github.com/dorayx/frock-middleware-cors
cors frock
Last synced: about 2 months ago
JSON representation
A simple CORS middleware for frock.
- Host: GitHub
- URL: https://github.com/dorayx/frock-middleware-cors
- Owner: dorayx
- License: wtfpl
- Created: 2016-03-05T18:11:17.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-17T15:38:25.000Z (almost 9 years ago)
- Last Synced: 2024-11-01T21:36:43.444Z (about 2 months ago)
- Topics: cors, frock
- Language: JavaScript
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# frock-middleware-cors
A simple frock middleware to enable CORS.
[![Build Status](https://img.shields.io/travis/dorayx/frock-middleware-cors/master.svg?style=flat-square)](https://travis-ci.org/dorayx/frock-middleware-cors/)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
[![npm](https://img.shields.io/npm/v/frock-middleware-cors.svg?style=flat-square)](https://www.npmjs.com/package/frock-middleware-cors)## Install
```
npm install --save-dev frock-middleware-cors
```## `frockfile` Example
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
}
}
]
}
]
}
]
}
```## `options` Configuration
### options.allowOrign: String|Array
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']
}
```### options.allowMethods: String|Array
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'
}
```### options.allowHeaders: String|Array
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'
}
```### options.allowCredentials: Boolean|String
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
}
```### options.maxAge: Integer|String
Indicates how long the results of a preflight request can be cached.
It defaults to `86400`.
```
options: {
maxAge: '86400'
}
```## License
[![WTFPL](http://www.wtfpl.net/wp-content/uploads/2012/12/wtfpl-badge-2.png)](http://www.wtfpl.net/)