Skip to content

Commit

Permalink
bump to v1
Browse files Browse the repository at this point in the history
  • Loading branch information
troygoode committed Apr 28, 2013
1 parent df83a42 commit 8a00e70
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
9 changes: 9 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ $ npm test
$ npm run lint
```

## Interactive Testing Harness

[http://node-cors-client.herokuapp.com](http://node-cors-client.herokuapp.com)

Related git repositories:

* [https://github.com/TroyGoode/node-cors-server](https://github.com/TroyGoode/node-cors-server)
* [https://github.com/TroyGoode/node-cors-client](https://github.com/TroyGoode/node-cors-client)

## License

[MIT License](http://www.opensource.org/licenses/mit-license.php)
27 changes: 24 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var express = require('express')
, cors = require('cors')
, app = express();

app.options('/products/:id', cors()); // enable preflight request
app.get('/products/:id', cors(), function(req, res, next){
res.json({msg: 'This is CORS-enabled for all origins!'});
});
Expand All @@ -49,7 +48,6 @@ var corsOptions = {
origin: 'http://example.com'
};

app.options('/products/:id', cors(corsOptions)); // enable preflight request
app.get('/products/:id', cors(corsOptions), function(req, res, next){
res.json({msg: 'This is CORS-enabled for only example.com.'});
});
Expand Down Expand Up @@ -77,7 +75,6 @@ var corsOptionsDelegate = function(req, callback){
callback(null, corsOptions); // callback expects two parameters: error and options
};

app.options('/products/:id', cors(corsOptionsDelegate)); // enable preflight request
app.get('/products/:id', cors(corsOptionsDelegate), function(req, res, next){
res.json({msg: 'This is CORS-enabled for a whitelisted domain.'});
});
Expand All @@ -87,6 +84,30 @@ app.listen(80, function(){
});
```

### Enabling CORS Pre-Flight

Certain CORS requests are considered 'complex' and require an initial
`OPTIONS` request (called the "pre-flight request"). An example of a
'complex' CORS request is one that uses an HTTP verb other than
GET/HEAD/POST (such as DELETE) or that uses custom headers. To enable
preflighting, you must add a new OPTIONS handler for the route you want
to support:

```javascript
var express = require('express')
, cors = require('cors')
, app = express();

app.options('/products/:id', cors()); // enable preflight request for DELETE request
app.del('/products/:id', cors(), function(req, res, next){
res.json({msg: 'This is CORS-enabled for all origins!'});
});

app.listen(80, function(){
console.log('CORS-enabled web server listening on port 80');
});
```

## Configuration Options

* `origin`: Configures the **Access-Control-Allow-Origin** CORS header. Expects a string (ex: "http://example.com"). Set to `true` to reflect the [request origin](http://tools.ietf.org/html/draft-abarth-origin-09), as defined by `req.header('Origin')`. Set to `false` to disable CORS.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cors"
, "version": "0.1.1"
, "version": "1.0.0"
, "author": "Troy Goode <troygoode@gmail.com> (https://github.com/troygoode/)"
, "description": "middleware for dynamically or statically enabling CORS in express/connect applications"
, "keywords": ["cors", "express", "connect", "middleware"]
Expand Down

0 comments on commit 8a00e70

Please sign in to comment.