News for hackers. Stuff that matters.
Re:Deploying front-end websites to S3 with CloudFront by wefarrell on Saturday February 15, 2020 @04:30PM (#22338121)
Configuring CORS is probably the biggest pain about this approach and is necessary if you want to send data to and from an API. This guide should probably mention it or link another guide.
Re:Deploying front-end websites to S3 with CloudFront by dragonwriter on Saturday February 15, 2020 @04:42PM (#22338194)
> Configuring CORS is probably the biggest pain about this approach and is necessary if you want to send data to and from an API.

CORS is only needed for the API, not the website, and only if you don't control the API or don't make it so the API can be served (from the client's perspective) from the same origin, perhaps because it's fronted by the same Cloudfront distribution.

Re:Deploying front-end websites to S3 with CloudFront by irjoe on Saturday February 15, 2020 @04:42PM (#22338193)
I've found a fairly workable solution is to have an origin for the API in CloudFront and a behaviour to route /api/* to that origin. Saves any CORS headaches. Obviously this won't work in all cases.
Re:Deploying front-end websites to S3 with CloudFront by saidmasoud on Saturday February 15, 2020 @11:34PM (#22339792)
Just remember, the route prefix you use to define the CloudFront behavior will also be added to the request sent to the origin server. So in this case, all routes defined by the API must be prefixed with `/api/`. This makes it hard to refactor existing APIs with many routes and dependencies, but works great in a greenfield scenario.

(Of course, you can rewrite the URL on the fly via Lambda@Edge but that's a PITA to maintain)

Re:Deploying front-end websites to S3 with CloudFront by hkchad on Saturday February 15, 2020 @08:39PM (#22339298)
Re:Deploying front-end websites to S3 with CloudFront by wefarrell on Saturday February 15, 2020 @04:58PM (#22338296)
Wasn't aware of this, will definitely try it next time around. Thanks!
Re:Deploying front-end websites to S3 with CloudFront by zelly on Saturday February 15, 2020 @04:53PM (#22338250)
Just change the Access-Control-Allow-Origin header. Am I missing something?
Re:Deploying front-end websites to S3 with CloudFront by wefarrell on Saturday February 15, 2020 @04:57PM (#22338287)
Access-Control-Allow-Credentials too and it needs to be configured on both the client and the server.
Re:Deploying front-end websites to S3 with CloudFront by zelly on Saturday February 15, 2020 @05:00PM (#22338305)
If the API is not yours, why not set up a proxy on your domain (where you can change the origin header)? Envoy, nginx, etc.
Re:Deploying front-end websites to S3 with CloudFront by avip on Saturday February 15, 2020 @05:48PM (#22338570)
What is the challenge setting up CORS on CloudFront?