-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot read property 'Access-Control-Request-Headers' of undefined Apollo-Server-Lambda #1560
Comments
Have confirmed that this is happening when an options request is sent to the API Endpoint, but I'm not really sure why event.headers is undefined in that case? |
Check this comment.
Here is the log for event and context without cors params to createHandler(). event.headers is missing. Only request payload is present.
And running using serverless offline. event.headers is present.
|
My observation was wrong in the above comment. The problem is because of the setting in API gateway. When you are using integration setting other than Also, the event object is constructed according to your setting in integration setting. When you test your lambda function in aws console without any parameters, you will also see this error since the request is not properly constructed through API gateway. (This is why I only got payload in the above comment.) You may find this helpful. You can also confirm it by checking this.
In my case, event.headers is already undefined since my API Gateway setting is not correct. If you are using multipart/form-data, it works using If you are using serverless, you will find it working on serverless-offline by just using ascii as encoding but when you deploy to API Gateway, the stream will be encoding wrongly. |
if you are testing in the AWS lambda console, you need to create a new test event json like:
|
Thanks for reporting this issue originally! I'm going to close this issue since it hasn't received a lot of traction and could have been resolved already. If this is still a problem, would someone who's experiencing the problem (or anyone who comes across this issue and is able to assist) mind building a reproduction of the problem in to a runnable CodeSandbox reproduction using the latest version of Apollo Server and sharing the link to that CodeSandbox in this issue? I'm happy to re-open if this is still occurring and someone can provide a reproduction. Thanks again! |
I am currently using Apollo-Server-Lambda 2.0.4
My lambda logs are showing a lot of instances of this error:
TypeError: Cannot read property 'Access-Control-Request-Headers' of undefined
at /var/task/node_modules/apollo-server-lambda/dist/ApolloServer.js:63:38
However, it looks like the request is still responding just fine to the client, so it isn't really breaking anything, but my lambdas are technically erroring out. I'm not really sure in what scenarios it is happening, but I'm thinking that it is the cors preflight check, as it happens before a lot of requests.
The text was updated successfully, but these errors were encountered: