corsen
A universal Cross-Origin Resource Sharing(CORS) middleware. Derrived from @koa/cors.
Installation
npm install corsen
or
yarn add corsen
Quick start
Enable cors with default options:
- origin: request Origin header
- allowMethods: GET,HEAD,PUT,POST,DELETE,PATCH
const http = const cors = // place your options here const server = http
cors(options)
/** * CORS middleware * * @param * - {String|Function(req, res)} origin `access-control-allow-origin`, default is request Origin header * - * - * - * - * - * @return * @api public */
Credit
All the commit before 71c4d00 are credited to koajs contributors.
Difference between corsen and @koa/cors
- The middleware function returned by
corsen
has a signature offunction(http.IncomingMessage, http.ServerResponse)
, while@koa/cors
recieves a koa'sContext
object. - All the header names set in
corsen
are lowercase. corsen
has removed the error handling utility of@koa/cors
. There is notkeepHeadersOnError
porperty in options.
Examples
felid-cors A Felid plugin for CORS.