Comments (14)
Thanks Cyu, you rock!
So I added this code to nginx:
http://davidwalsh.name/cdn-fonts
location ~* \.(eot|ttf|woff)$ {
add_header Access-Control-Allow-Origin *;
}
Which works when I query the Asset using CURL:
root@staging:/u/apps/test/current# curl -I https://staging.test.com/assets/fonts/snapy.woff
HTTP/1.1 200 OK
Server: nginx/1.2.6
Date: Thu, 25 Sep 2014 18:38:49 GMT
Content-Type: application/octet-stream
Content-Length: 11632
Last-Modified: Thu, 25 Sep 2014 17:49:34 GMT
Connection: keep-alive
Access-Control-Allow-Origin: *
Accept-Ranges: bytes
It was still failing, but I had to let the nginx cache-out for it to work again from a different domain.
Thanks!
from rack-cors.
Finally found this after much headache. Thanks for posting @GermanDZ - this should really be added to the doc
from rack-cors.
@hspinks feel free to use rephrase me to submit a PR to rack-cors project.
from rack-cors.
from rack-cors.
So I tried taking this into consideration and am still having issues on fonts. I'm not using Heroku, but Passenger Mod on Nginx. I'll keep investigating but I can't find much related to rails-cors.
Font from origin 'https://staging.site.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://blog.site.com' is therefore not allowed access.
from rack-cors.
What does your Nginx config look like?
from rack-cors.
My nginx config doesn't contain anything related to CORS. It use to, but I could never get it to properly work when I started using calls besides GET against my API.
Here was a good doc that started me down that path:
http://enable-cors.org/server_nginx.html
And here's the doc that lead me to trying to get the rails app to respond to CORS instead of Nginx:
http://codeodor.com/index.cfm/2011/7/26/Responding-to-the-OPTIONS-HTTP-method-request-in-Rails-Getting-around-the-Same-Origin-Policy/3387
Which lead me to rails-cors.
from rack-cors.
May be you can try http://rubygems.org/gems/font_assets (https://github.com/ericallam/font_assets). I use it successfully for fonts.
from rack-cors.
Hmm, I'll give it a shot. Hopefully wildcard origins work in that config setting?
config.font_assets.origin = '*'
from rack-cors.
Unfortunately, that did not work. Headers are still the same:
Remote Address:192.241.187.165:443
Request URL:https://staging.site.com/assets/fonts/snapy.woff
Request Method:GET
Status Code:200 OK (from cache)
Request Headers
Provisional headers are shown
Origin:http://blog.site.com
Referer:https://staging.site.com/assets/stylesheets/embedded.css?v=1411667741273
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.122 Safari/537.36
X-DevTools-Emulate-Network-Conditions-Client-Id:534EBD0C-33AC-F0E4-FEE4-1D45D09674DE
Response Headers
Accept-Ranges:bytes
Content-Length:11632
Content-Type:application/octet-stream
Date:Thu, 25 Sep 2014 17:55:27 GMT
Last-Modified:Thu, 25 Sep 2014 17:49:34 GMT
Server:nginx/1.2.6
I also use to have the following in my nginx config, though it now breaks the entire API, including GET requests from the API:
add_header 'Access-Control-Allow-Origin' $http_origin;
from rack-cors.
I ask about your Nginx config because if your font files are static then they're likely being served directly by Nginx and bypassing the Rails stack altogether. Doing a quick search I couldn't find away to turn this behavior off.
from rack-cors.
Thanks GermanDZ
from rack-cors.
hey! @1updesign this is shocking… our company is called @1uptalent :)
from rack-cors.
this is the setting for my cors, and still does not work when deploying to heroku, any suggestions
config.middleware.insert_before ActionDispatch::Static, Rack::Cors, :debug => true, :logger => (-> { Rails.logger }) do
allow do
origins ''
resource '/cors',
:headers => :any,
:methods => [:post],
:credentials => true,
:max_age => 0
resource '',
:headers => :any,
:methods => [:get, :post, :delete, :put, :patch, :options, :head],
:max_age => 0
end
end
from rack-cors.
Related Issues (20)
- Version 2.0 on RubyGems HOT 1
- Invite more maintainers HOT 1
- Doesn't append Access-Control-Allow-Origin header as response HOT 4
- Rails 7 and ros-apartment login logout set up HOT 1
- the Vary header does not seem to be set for CORS pre-flight checks that use the OPTIONS method HOT 1
- Controller still executes the request although CORS is blocked for this source HOT 1
- Support for Timing-Allow-Origin HOT 5
- Tag for v2.0.0 is missing HOT 3
- Does not work with Rack 3.0.0 HOT 1
- My CORS setup blocks bad urls but not POSTMAN requests HOT 3
- Vulnerabilities in included mocha.js HOT 1
- Stripe api with Cloud9 setup
- Is there any CI? HOT 1
- Cookie session related middleware interferes HOT 3
- Remove/Replace Rack::Utils::HeaderHash HOT 7
- delete the confusing `2.0.0` tag since `v2.0.0` exists? HOT 1
- issue comeback duplicate headers because of header name case HOT 3
- Release version 2.0.1 HOT 2
- How to add Access-Control-Allow-Private-Network header in Option response?
- Why is Rails.application.config.hosts required? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rack-cors.