2.2.2 • Published 6 years ago

kcors v2.2.2

Weekly downloads
22,948
License
MIT
Repository
github
Last release
6 years ago

@koa/cors

NPM version build status Test coverage David deps npm download

Cross-Origin Resource Sharing(CORS) for koa

Installation

$ npm install @koa/cors@2 --save

Quick start

Enable cors with default options:

  • origin: request Origin header
  • allowMethods: GET,HEAD,PUT,POST,DELETE,PATCH
const Koa = require('koa');
const cors = require('@koa/cors');

const app = new Koa();
app.use(cors());

cors(options)

/**
 * CORS middleware
 *
 * @param {Object} [options]
 *  - {String|Function(ctx)} origin `Access-Control-Allow-Origin`, default is request Origin header
 *  - {String|Array} allowMethods `Access-Control-Allow-Methods`, default is 'GET,HEAD,PUT,POST,DELETE,PATCH'
 *  - {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} cors middleware
 * @api public
 */

License

MIT

2.2.2

6 years ago

1.3.3

7 years ago

1.3.2

7 years ago

2.2.1

7 years ago

1.3.1

8 years ago

2.2.0

8 years ago

1.3.0

8 years ago

2.1.1

8 years ago

1.2.1

8 years ago

2.1.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

2.0.0

8 years ago

1.0.1

9 years ago

1.0.0

9 years ago