-
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
Update Lambda README to include more examples #330
Conversation
Thanks! |
output.headers['Access-Control-Allow-Origin'] = '*'; | ||
callback(error, output); | ||
}; | ||
const handler = server.graphqlLambda({ schema: myGraphQLSchema }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my implementation
set CORS_ORIGINS in lambda environment variable
CORS_ORIGINS="http://localhost:8080,http://example.com,https://example.com"
var corsOrigins = process.env.CORS_ORIGINS
// ......
server.graphqlLambda({
//...
})(event, context, function(err, output) {
var matchedCORS = corsOrigins
.split(",")
.map(function(o) { return o.trim(); })
.filter(function(o) { return o === event.headers.origin; });
if (matchedCORS.length > 0) {
output.headers = output.headers || {};
output.headers['Access-Control-Allow-Credentials'] = 'true';
output.headers['Access-Control-Allow-Origin'] = event.headers.origin;
}
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this example and will use it in my project. It might be a little complex for the README but it does show how to validate domain names instead of just allowing everything. I think I will add one more example that checks the origin of the request. Thanks.
This commit adds examples for modifying the response headers, to enable CORS, and how to read the event and context variables using an options function
LGTM in general, but im less familiar with aws, |
@NeoReyad is just my work account, I use this account more often, but wrote the integration for work. I will probably have to add some more debugging information later on since several questions still come up. |
oh cool 👍 |
This commit adds examples for modifying the response headers, to enable CORS, and how to read the event and context variables using an options function.
The lack of documentation has been brought up in the original PR and in this issue:
#315
TODO: