Reputation: 15434
Currently I have CloudFront distribution that serves SPA (spa.myapp.com
) from S3 bucket. I have also web server deployed in k8s on AWS.
Is it possible to forward all POST spa.myapp.com/* requests to my web server instead? What components / configuration I need to do this?
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.
Upvotes: 0
Views: 855
Reputation: 16775
*
path you should allow all kind of methods:From the docs:
CloudFront always caches responses to
GET
andHEAD
requests. You can also configure CloudFront to cache responses to OPTIONS requests. CloudFront does not cache responses to requests that use the other methods.
This means that POST
requests are always redirected to the origin (back-end), responses to these requests wont be cached. GET
and HEAD
requests may also be redirected, if there is a cache miss. Otherwise, the data from the cache is returned.
*
: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:
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.
Upvotes: 2