Skip to content

Instantly share code, notes, and snippets.

@oakbow
Last active August 29, 2015 13:58
Show Gist options
  • Save oakbow/10020623 to your computer and use it in GitHub Desktop.
Save oakbow/10020623 to your computer and use it in GitHub Desktop.
heroku+CloudFrontで静的ファイルを配信する(Webフォント対応) ref: http://qiita.com/Oakbow/items/9ceb93d47d918aeafe3a
# Allow font files to be loaded from anywhere (for loading webfonts in Firefox)
require 'rack/cors'
use Rack::Cors do
allow do
origins '*'
resource '/assets/icomoon/*', headers: :any, methods: :get
end
end
#- See more at: http://singlebrook.com/blog/cloudfront-cdn-with-rails-on-heroku#sthash.TTdcfp2x.dpuf
HTTP/1.1 200 OK
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: http://appname.herokuapp.com
Access-Control-Expose-Headers:
Access-Control-Max-Age: 1728000
Age: 0
Content-length: 28964
Content-Type: application/font-woff
Date: Mon, 07 Apr 2014 12:45:48 GMT
Last-Modified: Mon, 07 Apr 2014 11:46:50 GMT
Status: 200 OK
Vary: Origin
X-Content-Digest: 62969ddfd28bad52bf01817e0ec1e3fe84bd8e25
X-Rack-Cache: miss, store
Connection: keep-alive
gem 'rack-cors', require: 'rack/cors'
config.action_controller.asset_host = "//#{ENV['CDN_ASSET_HOST']}" unless ENV['CDN_ASSET_HOST'].blank?
@font-face {
font-family: 'icomoon';
src:url('<%= asset_path 'icomoon/icomoon.eot' %>');
src:url('<%= asset_path 'icomoon/icomoon.eot' %>?ie01');
src:url('<%= asset_path 'icomoon/icomoon.eot' %>?ie02');
src:url('<%= asset_path 'icomoon/icomoon.eot' %>?ie03');
src:url('<%= asset_path 'icomoon/icomoon.eot'%>?#iefix') format('embedded-opentype'),
url('<%= asset_path 'icomoon/icomoon.woff' %>') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?ie01') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?ie02') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?ie03') format('woff'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>') format('truetype'),
url('<%= asset_path 'icomoon/icomoon.svg' %>#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
/* Firefox hack start */
@-moz-document url-prefix('http://appname.herokuapp.com') {
@font-face {
font-family: 'icomoon';
src:url('<%= asset_path 'icomoon/icomoon.woff' %>?firefox01') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?firefox02') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?firefox03') format('woff'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>?firefox01') format('truetype'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>?firefox02') format('truetype'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>?firefox03') format('truetype');
font-weight: normal;
font-style: normal;
}
}
@-moz-document url-prefix('https://appname.herokuapp.com') {
@font-face {
font-family: 'icomoon';
src:url('<%= asset_path 'icomoon/icomoon.woff' %>?firefox_ssl01') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?firefox_ssl02') format('woff'),
url('<%= asset_path 'icomoon/icomoon.woff' %>?firefox_ssl03') format('woff'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>?firefox_ssl01') format('truetype'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>?firefox_ssl02') format('truetype'),
url('<%= asset_path 'icomoon/icomoon.ttf' %>?firefox_ssl03') format('truetype');
font-weight: normal;
font-style: normal;
}
}
/* Firefox hack end */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment