0

I am currently hosting a static single-page web application with AWS CloudFront. I would like to add a backend service for my web ui/client to communicate with so that I can serve dynamic content.

Specifically, I am concerned about same-origin policy. I have configured GoDaddy's DNS to forward traffic for my domain example.com to my AWS CloudFront endpoint using a CNAME record as described in [1]. I am also using a CNAME to forward www.example.com to example.com. Ideally, I'd like to add another subdomain for my backend called foo.example.com, with another CNAME record pointing to it. Then, my static content could communicate with foo.example.com.

However, after reading [2], it seems that this still breaks the Same-Origin Policy. To be considered the same origin, the entire domain (including the subdomain) must match. CORS (see [3]) doesn't seem like a viable option since it can't be used within JS and thus seems to be limited to more static content or Iframes. Anyways, it seems really heavy-handed when all I really need is for two sub-domains that I own to communicate with each other.

How is this usually done? I'd like to avoid setting up my own load-balancer in front of CloudFront since I want to utilize its speed and efficiency as a global CDN.

[1] https://medium.com/@brodartec/hosting-a-static-site-with-https-enabled-using-aws-s3-cloudfront-and-godaddy-826dae41fdc6

[2] https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy

[3] https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.