1.0.3 • Published 5 years ago

@cloudseat/micro-cors v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

A simple CORS middleware for Zeit's Micro, but also works well with all standard http.IncomingMessage and http.ServerResponse objects.

Installation

npm install @cloudseat/micro-cors

Usage

const cors = require('@cloudseat/micro-cors')

module.exports = cors()((req, res) => {
    res.end('hello')
})

or sets some options:

const cors = require('@cloudseat/micro-cors')
const options = {
    allowCredentials: true, // default
    allowOrigins: ['a.com', 'b.com'], // default ['*']
    allowMethods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS', 'PATCH'], // default
    allowHeaders: ['Authorization', 'Accept', 'Content-Type'], // default
    exposeHeaders: [], // default
    maxAge: 60 * 60 * 24 // defaults to 24 hours
}

module.exports = cors(options)((req, res) => {
    res.end('hello')
})