Skip to content

CORS Cross Domain Support

dougc84 edited this page Sep 19, 2014 · 2 revisions

CORS/Cross-Domain Support

Production

If you are using an external CDN or a separate subdomain (or subdomains) to host your Rails assets and have issues with Font-Awesome icons displaying properly, you will need to configure support for CORS (Cross-Origin Resource Sharing).

If you are using Nginx or Apache, you will need to specify the Access-Control-Allow-Headers, Access-Control-Allow-Methods, and Access-Control-Allow-Origin headers, at a minimum, for your assets. There are many resources on the web for configuring Nginx or configuring Apache, all of which provide different levels of security and configuration.

If you are using a CDN, such as Rackspace, Amazon S3, or Amazon CloudFront, check with your CDN provider on how to configure CORS for your bucket. Here are a few resources to get started, but check your CDN server's documentation for the best and most up-to-date information:

Development

If you are working in development mode and have an application that uses subdomains locally (configured through your /etc/hosts file, Pow, or dnsmasq), you may encounter the same issues with rendering fonts. Since you are most likely not running your development server proxied behind Apache or Nginx, you are serving up your assets on the fly through your Rails server itself. The solution is to add the rack-cors gem to your Gemfile in the development group to enable CORS configuration from your application:

gem "rack-cors", group: :development

Don't forget to bundle install, and follow the directions on the rack-cors readme file to set it up. The example provided in their readme works well - simply add it to the top of your development.rb file (inside of the configuration block) instead of in the application.rb file. Restart your server, and Font-Awesome icons should appear like they should.

Please note: The developer of this app is not affiliated with Nginx, Apache, or rack-cors, and will not provide support for any CORS-related issues.

Clone this wiki locally