3 ms·
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 menti
by wefarrell 7y ago
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.
- irjoe 7y agoI'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.
- wefarrell 7y agoWasn't aware of this, will definitely try it next time around. Thanks!
- hkchad 7y agoHere's a writeup on the details. https://medium.com/@chad.h.dalton/how-we-reduced-our-api-calls-by-50-c2d25599f9d8 https://medium.com/@chad.h.dalton/how-we-reduced-our-api-cal...
- saidmasoud 7y agoJust 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)
- dragonwriter 7y ago> 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.
- zelly 7y agoJust change the Access-Control-Allow-Origin header. Am I missing something?
- avip 7y agoWhat is the challenge setting up CORS on CloudFront?