@cloudseat/micro-cors

A simple CORS middleware for Zeit's Micro

Usage no npm install needed!

<script type="module">
  import cloudseatMicroCors from 'https://cdn.skypack.dev/@cloudseat/micro-cors';
</script>

README

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')
})