Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/maccyber/micro-cors
Simple CORS middleware for Zeit's Micro
https://github.com/maccyber/micro-cors
Last synced: about 2 months ago
JSON representation
Simple CORS middleware for Zeit's Micro
- Host: GitHub
- URL: https://github.com/maccyber/micro-cors
- Owner: maccyber
- Created: 2017-10-10T14:02:17.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T20:32:18.000Z (about 1 year ago)
- Last Synced: 2024-04-28T02:36:38.055Z (9 months ago)
- Language: JavaScript
- Size: 41 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[![Build Status](https://travis-ci.org/maccyber/micro-cors.svg?branch=master)](https://travis-ci.org/maccyber/micro-cors)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)# CORS middleware for Micro
### Summary
Simple [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS) middleware for Zeit's [Micro](https://github.com/zeit/micro)
### Install
```
npm i --save micro-cors
```### Usage
Basic
```js
const cors = require('micro-cors')()
const handler = (req, res) => send(res, 200, 'ok!')module.exports = cors(handler)
```With options
```js
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
```js
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)
```#### Options
##### `allowMethods`
default: `['POST','GET','PUT','DELETE','OPTIONS']`
##### `allowHeaders`
default: `['X-Requested-With','Access-Control-Allow-Origin','X-HTTP-Method-Override','Content-Type','Authorization','Accept']`
##### `exposeHeaders`
default: `[]`
##### `maxAge`
default: `86400`
##### `origin`
default: `*`