我的引導glyphicons顯示在其他瀏覽器,但我得到谷歌瀏覽器這個錯誤:請求的資源上是否存在「Access-Control-Allow-Origin」頭?
從原點「http://d37p52igaahgm9.cloudfront.net」字體已 加載由跨來源資源共享政策阻止:無 「訪問 - 「Control-Allow-Origin」標題出現在請求的 資源中。原因'http://www.anthonygalli.com'因此不允許 允許訪問。
的錯誤仍然存在,儘管嘗試:
application_controller.rb
before_action :set_cors
def set_cors
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Request-Method'] = '*'
end
application.rb中
config.middleware.insert_before 0, "Rack::Cors" do
allow do
origins '*'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
end
config.action_dispatch.default_headers = {
'Access-Control-Allow-Origin' => '*',
'Access-Control-Request-Method' => '*'
}
CORS配置編輯器
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>https://www.anthonygalli.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>https://anthonygalli.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Content-*</AllowedHeader>
<AllowedHeader>Host</AllowedHeader>
</CORSRule>
</CORSConfiguration>
參考文獻
- Amazon S3 CORS (Cross-Origin Resource Sharing) and Firefox cross-domain font loading
- Font from origin has been blocked from loading by Cross-Origin Resource Sharing policy