Skip to content

Commit

Permalink
Fix, prevent options handler to be added when cors is not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
nrako committed Jan 29, 2017
1 parent 5371f24 commit 5d81f73
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 2 additions & 5 deletions lib/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ module.exports = {
}
const path = endpoint.replace(/\{(.+?)\}/g, ':$1');
let handler = this._handlerBase(funcConf, httpEvent);
let optionsHandler = this._optionsHandler;
if (httpEvent.cors) {
handler = this._handlerAddCors(handler);
optionsHandler = this._handlerAddCors(optionsHandler);
}
if (method !== 'any') {
app.options(path, optionsHandler);
let optionsHandler = this._handlerAddCors(this._optionsHandler);
if (method !== 'any') app.options(path, optionsHandler);
}
app[method === 'any' ? 'all' : method](
path,
Expand Down
6 changes: 1 addition & 5 deletions tests/serve.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,15 +339,11 @@ describe('serve', () => {
expect(module.serverless.cli.consoleLog).to.have.been.calledWith(
' POST - http://localhost:8000/test/func2path/{testParam}'
);
expect(app.options).to.have.callCount(2);
expect(app.options).to.have.callCount(1);
expect(app.options.firstCall).to.have.been.calledWith(
'/test/func1path',
testHandlerCors
);
expect(app.options.secondCall).to.have.been.calledWith(
'/test/func2path/:testParam',
testHandlerOptions
);
});

it('should create express handler for all methods for functions with "any" method', () => {
Expand Down

0 comments on commit 5d81f73

Please sign in to comment.