Skip to content

More cache behavior options. #6

@Pavel910

Description

@Pavel910

So today I ran into a problem where I'm deploying an Apollo Server for my GraphQL API and CloudFront is causing a few problems:

  1. it is not forwarding several headers that are important for my API (Accept and Accept-Language), that behavior is documented in official AWS docs.

  2. by default POST requests are not allowed, and GraphQL runs on POST most of the time.

Proposed solution

Introduce more options to @serverless/aws-cloudfront component to allow headers and methods customization. Here is an example:

distribution:
  component: '@serverless/aws-cloudfront'
  inputs:
    origins:
      - url: ${api.url}
        pathPatterns:
          "*":
            ttl: 0
            forward:
              headers: ["Accept", "Accept-Language"]
            allowedMethods: ["GET", "HEAD", "OPTIONS", "PUT", "POST", "PATCH", "DELETE"]

@eahefnawy This is related to the issue in aws-api-gateway repo. I know this looks like too many options, but since CloudFront is a quirky CDN, I can't seem to find a cleaner solution to the problem.

I'd be glad to send a PR, but I want to hear your opinion on this first.

Cheers! 🍻

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions