包详细信息

kcors

koajs82.8kMIT2.2.2

Cross-Origin Resource Sharing(CORS) for koa

cors, koa-cors, Cross-Origin Resource Sharing, @koa/cors

自述文件

@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 / 2018-07-11

others

2.2.1 / 2017-02-12

  • fix: always set "Vary: Origin" header (#31)

2.2.0 / 2016-09-26

  • feat: add PATCH to default methods

2.1.1 / 2016-05-14

  • fix: keepHeadersOnError won't affect OPTIONS request (#17)

2.1.0 / 2016-04-29

  • feat: Keep headers after an error (#13)
  • chore: use eslint instead of jshint (#10)
  • test: use codecov instead of coveralls

2.0.0 / 2016-02-20

  • chore: make node engines >= 4.3.1
  • doc: update example
  • test: only test on node 4+
  • refactor: src,test: update to (ctx, next) -> Promise middleware contract
  • chore: base on koa@2

1.0.1 / 2015-02-11

  • fix: make more spec-compliant

1.0.0 / 2015-02-09

  • first release