Four Cache Behaviours are created in CloudFront.
The first two
static/* forward the requests to S3.
The third is associated to a lambda function which is responsible for handling three types of requests.
Server side rendered page. Any page that defines
getServerSidePropsmethod will be rendered at this level and the response is returned immediately to the user.
Statically optimised page. Requests to pages that were pre-compiled by next to HTML are forwarded to S3.
Public resources. Requests to root level resources like
/manifest.json, etc. These are forwarded to S3.
The reason why 2. and 3. have to go through [email protected] first is because the routes don't conform to a pattern like
static/*. Also, one cache behaviour per route is a bad idea because CloudFront only allows 25 per distribution.
The fourth cache behaviour handles next API requests