/micro-cors

Simple CORS middleware for Zeit's Micro

Primary LanguageJavaScriptMIT LicenseMIT

CORS middleware for Micro

Summary

Simple CORS middleware for Zeit's Micro

CircleCI

We're working on v1, come help us out.

Install

yarn add micro-cors

Usage

Basic

const { send } = require('micro')
const cors = require('micro-cors')()
const handler = (req, res) => send(res, 200, 'ok!')

module.exports = cors(handler)

With options

const { send } = require('micro')
const microCors = require('micro-cors')
const cors = microCors({ allowMethods: ['PUT', 'POST'] })
const handler = (req, res) => send(res, 200, 'ok!')

module.exports = cors(handler)

Options

allowMethods

default: ['POST','GET','PUT','PATCH','DELETE','OPTIONS']

allowHeaders

default: ['X-Requested-With','Access-Control-Allow-Origin','X-HTTP-Method-Override','Content-Type','Authorization','Accept']

allowCredentials

default: true

exposeHeaders

default: []

maxAge

default: 86400

origin

default: *