@ahanapediatrics/cors
v4.0.1
Published
Cross-Origin Resource Sharing(CORS) for koa
Downloads
24
Readme
@ahanapediatrics/cors
Cross-Origin Resource Sharing(CORS) for koa
Installation
$ npm install @ahanapediatrics/cors --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('@ahanapediatrics/cors');
const app = new Koa();
app.use(cors());
cors(options)
/**
* CORS middleware
*
* @param {CORSOptions} [options]
* @param [options.origin] `Access-Control-Allow-Origin`, default is request Origin header
* @param [options.allowMethods] `Access-Control-Allow-Methods`, default is 'GET,HEAD,PUT,POST,DELETE,PATCH'
* @param [options.exposeHeaders] `Access-Control-Expose-Headers`
* @param [options.allowHeaders] `Access-Control-Allow-Headers`
* @param [options.maxAge] `Access-Control-Max-Age` in seconds
* @param [options.credentials] `Access-Control-Allow-Credentials`
* @param [options.keepHeadersOnError] Add set headers to `err.header` if an error is thrown
*
* @return {Middleware} Koa middleware
* @api public
*/