![]() ![]() I guess CloudFront cache sticks around longer than I had thought. You can explicitly invalidate cached assets by going to the CloudFront distribution's Invalidations tab and creating an invalidation for *. The last thing I did that finally made these settings stick was invalidate the CloudFront cache. Paste the following into the custom box one at a time and click Add Custom>Īfter messing with this for over 6 hours, I think I messed it up even more.Whitelist Headers: Select Origin and click Add >.select the behavior (there will probably be only one).I preferred not to leave it wide open and just use the domains I knew I would hit it with. Here's what I did to get it to work: Installed rack-cors gem 'rack-cors'Ĭonfig/initializers/rack-cors.rb if defined? Rack::Cors I recently tried to use Font Awesome with Heroku and CloudFront on Rails 5 and faced a similar problem. I thought I would put my two cents in on this issue. I have a few workarounds in mind like excluding fonts from cloudfront or uploading fonts to S3 (of course with cloudfront pointing to bucket) and adding the new source path in css files, but I would rather do the proper fix with allowed headers. This error is super weird because basically says !=. Origin ' ' is therefore not allowed access. If I set the allowed headers to my cloudfront distribution name then I get this error:Īccess to Font at ' ' from origin ' ' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header has a value ' ' that is not equal to the supplied origin. This ( ) seems to be quiet a resource, but didn't solve the problem with rails 5. What did I miss? How can I make this work again? Reply The problem could be that the forwarded headers in the behavior are set like this: Access-Control-Allow-OriginĪs far as I know rails5 works with 12factors out of the box, so I don't have to add rve_static_assets = true if my RAILS_SERVE_STATIC_FILES env var is set to enabled (which happens automatically with heroku). The behavior path pattern is set to default and it's connected to the herokuapp. I likely didn't mess up the basic cloudfront config, because it was working before I started tweaking with the fonts. ![]() Resource '/assets/*', headers: :any, methods: ![]() Initializes/cors.rb (added the cors gem) .insert_before 0, Rack::Cors do Production.rb config.action_controller.asset_host = ENVĬonfig.static_cache_control = 'public, max-age=31536000' ![]() I didn't really understand the problem because I thought I had everything properly configured: Origin '' is therefore not allowed access. I could make it work for the assets, then I tried to add the config for the fonts as well, but I just screwed up everything and none of them works.Īt the moment for the assets I get 404 error: Failed to load resource: xzy.cloudfront/assets/application-12341234.css the server responded with a status of 404 ()įor the prev version when the assets worked but the fonts didn't, I got this error (I don't remember what was the diff between the 2 setup): Access to Font at '' from origin '' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. I tried to configure a rails5 app (deployed on heroku) with cloudfront for assets and fonts. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |