Package Exports
- kcors
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (kcors) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
kcors
Cross-Origin Resource Sharing(CORS) for koa
Installation
$ npm install kcors@2 --saveQuick start
Enable cors with default options:
- origin: *
- allowMethods: GET,HEAD,PUT,POST,DELETE
const Koa = require('koa');
const cors = require('kcors');
const app = new Koa();
app.use(cors());cors(options)
/**
* CORS middleware
*
* @param {Object} [options]
* - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is '*'
* - {String|Array} allowMethods `Access-Control-Allow-Methods`, default is 'GET,HEAD,PUT,POST,DELETE'
* - {String|Array} exposeHeaders `Access-Control-Expose-Headers`
* - {String|Array} allowHeaders `Access-Control-Allow-Headers`
* - {String|Number} maxAge `Access-Control-Max-Age` in seconds
* - {Boolean} credentials `Access-Control-Allow-Credentials`
* - {Boolean} keepHeadersOnError Add set headers to `err.header` if an error is thrown
* @return {Function}
* @api public
*/