CORS issue, using Rack-cors gem with cloudfront assets
See original GitHub issueI have a rails 4 app hosted on AWS with assets served on cloudfront. I use the rack-cors gem to add cors headers. My rack-cors settings allows only check for my domain hence cannot provide jsfiddle example.
curl -H "Origin:https://staging.beenlightened.com" -I https://d3czu6zp3f06wr.cloudfront.net/assets/vitality4-064f8c9848768917287e1a7dbcec1749.png
Notice CORS headers are added correctly. However html2canvas still complains about cors headers not being present.
Issue Analytics
- State:
- Created 7 years ago
- Comments:8
Top Results From Across the Web
Cloudfront CORS issue serving fonts on Rails application
The rack-cors gem implements the CORS protocol in a Rack middleware. In addition to setting Access-Control-Allow-Origin and related headers ...
Read more >CORS issue with Rails app and AWS Cloudfront(?) - Fly.io
I'm using the rack-cors gem and an initializer that includes all my origins (the Rails app on fly.io as well as the Cloudfront...
Read more >Various CORS issues related (not only to) Ruby on Rails
I'm writing this article after week full of CORS issues that I've ... Ruby on Rails asset files under CDN pointing to other...
Read more >Notes on Cloudfront in front of Rails Assets on Heroku, with ...
AWS docs here and here suggest for CORS support you also need to configure the Cloudfront distribution to forward additional headers — Origin, ......
Read more >Cross-Origin Resource Sharing | reinteractive
Happily, the solution was quite simple. Use the rack-cors gem (source code). Because we aren't using S3 for our assets, we just need...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From what I remember: When the page loads the first time, the browser caches the image. Since the domain is the same, the CORS headers are not present. So now when I try to print the image it used the cached image and html2canvas complained about CORS headers not present.
My only solution was to add a timestamp in the ImageContainer method inside the library like so:
I’ve spent ages on this damn thing. Hope it works for you man.
Can you make an example on codepen or jsfiddle?