Skip to content

Commit

Permalink
Default routeCorsConfig to empty object to avoid errors with the `r…
Browse files Browse the repository at this point in the history
…outeCorsConfig.origin` reference below.

See #3662.  The test would never fail currently b/c Express 3 catches the thrown error, but good to have the test for the future so we're not using that as a crutch.

closes #3662
  • Loading branch information
sgress454 committed Mar 23, 2016
1 parent c1306e5 commit 7b6e786
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* [BUGFIX] Update validation rules from anchor [3649](https://github.com/balderdashy/sails/issues/3649)
* [BUGFIX] Respond with an error if attempting to use `req.file()` from a virtual request (i.e. when Skipper is not available). And don't pass in `res` when building the mock request, since it is not available yet. [3656](https://github.com/balderdashy/sails/issues/3656)
* [BUGFIX] Fix incorrect handling of errors in responses hook. Thanks [@tapuzzo-fsi](https://github.com/tapuzzo-fsi)! [3645](https://github.com/balderdashy/sails/pull/3645)
* [BUGFIX] Fix error from `routeCorsConfig` sometimes being undefined [3662](https://github.com/balderdashy/sails/issues/3662)
* [INTERNAL] Replace `ready` event with an async `handleLift` lifecycle callback in order to simplify the behavior of `sails lift` and ensure the timing of the "done" callback is correct when using it programmatically.
* [INTERNAL] Massive overhaul of tests. See [b033f2d thru e85810a](https://github.com/balderdashy/sails/compare/71aa56db59129da58825b22f32030234a4f5ae2c...b033f2d9af4953fd65c3e1bbb44ed4df15da1f68).
* [INTERNAL] Extrapolate ORM hook into sails-hook-orm.
Expand Down
2 changes: 1 addition & 1 deletion lib/hooks/cors/to-prepare-send-headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = function (sails) {
// that would be used in the follow-on request
if (isOptionsRoute) {
var method = (req.headers['access-control-request-method'] || '').toLowerCase() || 'default';
routeCorsConfig = _routeCorsConfig[method];
routeCorsConfig = _routeCorsConfig[method] || {};
if (routeCorsConfig == 'clear') {
return clearHeaders(req, res, next);
}
Expand Down
28 changes: 28 additions & 0 deletions test/integration/router.specifiedRoutes.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,34 @@ describe('router :: ', function() {
appHelper.teardown();
});

describe('an options request', function() {
before(function() {
httpHelper.writeRoutes({
'/*': {
cors: true,
},
'/testRoute': {
controller: 'test',
action: 'verb',
},
});
});

it('should respond to OPTIONS requests', function(done) {
httpHelper.testRoute('options', {
url: 'testRoute',
headers: {
'Access-Control-Request-Method': 'post',
Origin: 'https://foo.shyp.com'
},
}, function(err, response, body) {
assert.equal(response.statusCode, 200);
assert.equal(response.headers['access-control-allow-origin'], 'https://foo.shyp.com');
done();
});
});
});

describe('with an unspecified http method', function() {

before(function() {
Expand Down

0 comments on commit 7b6e786

Please sign in to comment.