Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @koa/cors with all npm packages installed. Try it out:

var cors = require("@koa/cors")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@koa/cors v3.0.0

Cross-Origin Resource Sharing(CORS) for koa


NPM version build status Test coverage David deps npm download

Cross-Origin Resource Sharing(CORS) for koa


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

Quick start

Enable cors with default options:

  • origin: request Origin header
const Koa = require('koa');
const cors = require('@koa/cors');

const app = new Koa();


 * 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



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free