Skip to content
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

Add CacheControl headers on the OPTIONS response in AWS API Gateway #5328

Merged
merged 4 commits into from
Oct 14, 2018

Conversation

reedyrm
Copy link
Contributor

@reedyrm reedyrm commented Sep 25, 2018

What did you implement:

Closes #5326

How did you implement it:

Added a conditional check when cacheControl property is present on a cors property for a function, it will add the value as the header for the response. This was only built for AWS API Gateway.

How can we verify it:

I have modified https://github.com/serverless/examples/tree/master/aws-node-simple-http-endpoint example to include the cors change. The cacheControl property is the only new thing that I added.

sample serverless.yml


service: serverless-simple-http-endpoint

frameworkVersion: ">=1.1.0 <2.0.0"

provider:
  name: aws
  runtime: nodejs4.3

functions:
  currentTime:
    handler: handler.endpoint
    events:
      - http:
          path: ping
          method: get
          cors:
            origin: '*'
            allowCredentials: true
            cacheControl: 'max-age=600, s-maxage=600'
            maxAge: 600
            headers:
              - Content-Type
              - X-Amz-Date
              - Authorization
              - X-Api-Key
              - X-Amz-Security-Token
              - X-Amz-User-Agent
              - Cache-Control

Todos:

  • Write tests
  • Write documentation
  • Fix linting errors
  • Make sure code coverage hasn't dropped
  • Provide verification config / commands / resources
  • Enable "Allow edits from maintainers" for this PR
  • Update the messages below

Is this ready for review?: YES
Is it a breaking change?: NO

@horike37 horike37 added this to the 1.33.0 milestone Oct 13, 2018
Copy link
Member

@horike37 horike37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@reedyrm
Thank you for your contribution 👍
Just tested and great to see working fine.

However, you didn't add an explanation of this feature to documentation.
Could you add it around the following section?
https://github.com/serverless/serverless/blob/master/docs/providers/aws/events/apigateway.md#enabling-cors

@reedyrm
Copy link
Contributor Author

reedyrm commented Oct 13, 2018

@horike37 Added documentation. Thank you for giving me a link to the documentation, I wasn't sure where it was.

@horike37
Copy link
Member

@reedyrm
Thank you for adding it! LGTM 👍

@horike37 horike37 merged commit 71214f5 into serverless:master Oct 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants