Simple CORS middleware for Zeit's Micro
npm i --save micro-cors
Basic
const cors = require('micro-cors')()
const handler = (req, res) => send(res, 200, 'ok!')
module.exports = cors(handler)
With options
const microCors = require('micro-cors')
const cors = microCors({ allowMethods: ['PUT', 'POST'] })
const handler = (req, res) => send(res, 200, 'ok!')
module.exports = cors(handler)
With multiple wrappers
const microCors = require('micro-cors')
const cors = require('micro-cors')()
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)))
const handle = async(req, res) => {
return `Hello world`
}
module.exports = compose(
cors,
anotherWrapper,
analitycsWrapper,
redirectWrapper,
yetAnotherWrapper
)(handle)
default: ['POST','GET','PUT','DELETE','OPTIONS']
default: ['X-Requested-With','Access-Control-Allow-Origin','X-HTTP-Method-Override','Content-Type','Authorization','Accept']
default: []
default: 86400
default: *