Hullo!
I’m trying to get on board with the new Serverless 1.0, and I’m having a bit of an issue with CORS.
I suspect there’s a tiny thing that I’ve missed in my setup.
To test, I’ve made a function called echo that returns the context and event data for a GET request.
My function is the following:
module.exports.echo = (event, context, cb) => {
context.succeed({
statusCode: 200,
headers: {
"Access-Control-Allow-Origin": "*"
}
});
cb(null, {context, event});
};
My yaml file includes the following:
echo:
handler: handler.echo
events:
- http:
path: echo
method: get
integration: lambda
cors:
origins:
- '*'
When access by URL I am returned the expected echo.
When I to get the resource by ajax, there is a CORS error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
https://??????.execute-api.us-east-1.amazonaws.com/dev/echo?{%22userId%22:%22dummyID%22}&_=??????.
(Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
What should I do to fix this?