Skip to content

Commit 5d81f73

Browse files
committed
Fix, prevent options handler to be added when cors is not enabled
1 parent 5371f24 commit 5d81f73

File tree

2 files changed

+3
-10
lines changed

2 files changed

+3
-10
lines changed

lib/serve.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ module.exports = {
5151
}
5252
const path = endpoint.replace(/\{(.+?)\}/g, ':$1');
5353
let handler = this._handlerBase(funcConf, httpEvent);
54-
let optionsHandler = this._optionsHandler;
5554
if (httpEvent.cors) {
5655
handler = this._handlerAddCors(handler);
57-
optionsHandler = this._handlerAddCors(optionsHandler);
58-
}
59-
if (method !== 'any') {
60-
app.options(path, optionsHandler);
56+
let optionsHandler = this._handlerAddCors(this._optionsHandler);
57+
if (method !== 'any') app.options(path, optionsHandler);
6158
}
6259
app[method === 'any' ? 'all' : method](
6360
path,

tests/serve.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,11 @@ describe('serve', () => {
339339
expect(module.serverless.cli.consoleLog).to.have.been.calledWith(
340340
' POST - http://localhost:8000/test/func2path/{testParam}'
341341
);
342-
expect(app.options).to.have.callCount(2);
342+
expect(app.options).to.have.callCount(1);
343343
expect(app.options.firstCall).to.have.been.calledWith(
344344
'/test/func1path',
345345
testHandlerCors
346346
);
347-
expect(app.options.secondCall).to.have.been.calledWith(
348-
'/test/func2path/:testParam',
349-
testHandlerOptions
350-
);
351347
});
352348

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

0 commit comments

Comments
 (0)