问题描述
最近,我们在CDN Cloudfront上移动了我们的资产。我们注意到,表面在Firefox上断开了。经过几分钟的搜索,这是一个CORS的故事。我们允许使用Cloudfront字段。
application_controller
:
after_filter:set_access_control_headers
def set_access_control_headers
headers ['Access-Control-Allow-Origin'] = CDN_CLOUDFRONT
end
production.rb
:
CDN_CLOUDFRONT =http://xxx.cloudfront.net
这个工作非常好,直到昨天。
/ div>
我没有使用Heroku设置,而是AFAIK(如),标头 Access-Control-Allow-Origin
应反映域的值消费来自CDN的静态资产。
例如:
对于托管在并使用中的资源
headers ['Access-Control-Allow-Origin'] ='http://mydomain.net'
将允许mydomain.net通过访问资产。换句话说,用您网站的域名替换 CDN_CLOUDFRONT
应该可以解决这个问题。
希望这有助于。 p>
PS:我不知道你的设置是如何工作的,直到昨天。 :)
PPS:在您的CDN中添加替代域名(CNAME)将有助于您在需要快速丢弃现有通过公开的分发,并开始使用新分发。如果您正在使用替代域名,例如。
Recently we moved our assets on a CDN Cloudfront. We have noticed that the surfaces were broken on Firefox. After a few minutes of searching, it was a story of CORS. We allowed the field Cloudfront.
application_controller
:
after_filter :set_access_control_headers
def set_access_control_headers
headers['Access-Control-Allow-Origin'] = CDN_CLOUDFRONT
end
production.rb
:
CDN_CLOUDFRONT = "http://xxx.cloudfront.net"
This worked very well until yesterday. After several searches and reflections, I have not found a solution.
Any idea?
I haven't worked with a Heroku setup, but AFAIK (and as illustrated at developer.mozilla.org), the header Access-Control-Allow-Origin
should reflect a value of the domain which consumes static assets from the CDN.
E.g.:For a website hosted at http://mydomain.net and consuming assets from http://wefe342r34r23.cloudfront.net
headers['Access-Control-Allow-Origin'] = 'http://mydomain.net'
Will allow mydomain.net to access assets via http://wefe342r34r23.cloudfront.net. In other words, replacing CDN_CLOUDFRONT
with your website's domain name should solve the problem.
Hope this helps.
P.S.: I'm not sure how your setup worked until yesterday. :)
P.P.S: Adding Alternate Domain Names (CNAMEs) to your CDN will help you in a scenario wherein you want to quickly discard an existing distribution exposed over http://xxx.cloudfront.net and start using a fresh distribution http://yyy.cloudfront.net. You won't need to change anything in your application codebase if you are using an Alternate Domain Name such as http://cdn.mydomain.net in that case.
这篇关于Heroku + CDN Cloudfront +字体 - Firefox错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!