I have a simple lambda function setup with a serverless.yml configuration. What I'm looking to do is to have an additional lambda function which would be called for OPTIONS method for any of the deployed lambda functions. For example, if /login is called with OPTIONS I want options handler to handle the execution. If /login is called with GET I want the actual login handler to handle the execution. Same for all the other handler functions as well.
Serverless.yml
functions:
login:
handler: handler.login
events:
- http:
path: login
method: get
stats:
handler: handler.Stats
events:
- http:
path: patientset/{id}/stats
method: get
options:
handler: handler.options
events:
- http:
path: '/' //Need something global like this
method: options
Handler.js
module.exports.options = (event) => {
const headers = setHeaders(event);
return {
statusCode: 200,
headers,
body: JSON.stringify({})
}
}
//Code updated in edit
login:
handler: handler.login
events:
- http:
path: login
method: get
cors:
origin: 'https://d2mo71maq8qx66.cloudfront.net'
headers: ${self:custom.ALLOWED-HEADERS}
allowCredentials: true