Simple CORS middleware for Zeit's Micro
Switch branches/tags
Clone or download
tim-phillips Tasks (#49)
* only run lint once
* add yarn integrity hashes
Latest commit 14ec915 Nov 25, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Filter Preflight only headers + allowCredentials option (#42) Oct 5, 2018
.gitignore Upgrade dependencies (#12) Apr 3, 2017
LICENSE Create LICENSE (#37) Aug 19, 2018
README.md Import send in examples (#44) Oct 9, 2018
circle.yml Fix CI (#22) May 10, 2017
package.json Tasks (#49) Nov 25, 2018
yarn.lock Tasks (#49) Nov 25, 2018

README.md

CORS middleware for Micro

Summary

Simple CORS middleware for Zeit's Micro

CircleCI

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: *