2014-05-07 23:07:32 -04:00
|
|
|
# restify-cors-middleware
|
|
|
|
|
|
|
|
> CORS middleware with full [W3C spec](www.w3.org/TR/cors) support.
|
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
```js
|
|
|
|
var corsMiddleware = require('restify-cors-middleware');
|
|
|
|
|
|
|
|
var cors = corsMiddleware({
|
2014-12-03 09:54:59 -05:00
|
|
|
preflightMaxAge: 5, //Optional
|
2014-05-07 23:07:32 -04:00
|
|
|
origins: ['http://api.myapp.com', 'http://web.myapp.com'],
|
|
|
|
allowHeaders: ['API-Token'],
|
|
|
|
exposeHeaders: ['API-Token-Expiry']
|
|
|
|
});
|
|
|
|
|
|
|
|
server.pre(cors.preflight);
|
|
|
|
server.use(cors.actual);
|
|
|
|
```
|
|
|
|
|
|
|
|
## Compliance to the spec
|
|
|
|
|
|
|
|
See [unit tests](https://github.com/TabDigital/restify-cors-middleware/tree/master/test)
|
|
|
|
for examples of preflight and actual requests.
|