Home > Back-end >  Can I reverse-proxy POST requests while using CloudFront CDN for GET requests?
Can I reverse-proxy POST requests while using CloudFront CDN for GET requests?

Time:01-25

Currently I have CloudFront distribution that serves SPA (spa.myapp.com) from S3 bucket. I have also web server deployed in k8s on AWS.

  1. Is it possible to forward all POST spa.myapp.com/* requests to my web server instead? What components / configuration I need to do this?

  2. Is it possible to forward all spa.myapp.com/api/* requests to my web server instead (regardless of http method)? What components / configuration I need to do this?

Generally I want to serve SPA from CDN but also have few endpoints server side on same domain.

CodePudding user response:

  1. On your CloudFront Behavior for * path you should allow all kind of methods:

enter image description here

From the enter image description here

You can have multiple behaviors, which can have different properties for caching. These behaviors are differentiated by their path pattern. They can also have a priority, the incoming requests are evaluated against higher precedence behaviors first. For example:

enter image description here

To answer your question, what you have to do is to create a different behavior for the /api/* path and apply a different configuration for this behavior. This has to have a higher precedence compared to the default behavior. Keep in mind that CloudFront caches GET, HEAD and OPTIONS requests only.

  •  Tags:  
  • Related