Giter Site home page Giter Site logo

Comments (14)

toobulkeh avatar toobulkeh commented on July 23, 2024 2

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.

hspinks avatar hspinks commented on July 23, 2024

👍

Finally found this after much headache. Thanks for posting @GermanDZ - this should really be added to the doc

from rack-cors.

GermanDZ avatar GermanDZ commented on July 23, 2024

@hspinks feel free to use rephrase me to submit a PR to rack-cors project.

from rack-cors.

chrisnicola avatar chrisnicola commented on July 23, 2024

👍 as well.

from rack-cors.

toobulkeh avatar toobulkeh commented on July 23, 2024

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.

cyu avatar cyu commented on July 23, 2024

What does your Nginx config look like?

from rack-cors.

toobulkeh avatar toobulkeh commented on July 23, 2024

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.

GermanDZ avatar GermanDZ commented on July 23, 2024

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.

toobulkeh avatar toobulkeh commented on July 23, 2024

Hmm, I'll give it a shot. Hopefully wildcard origins work in that config setting?

config.font_assets.origin = '*'

from rack-cors.

toobulkeh avatar toobulkeh commented on July 23, 2024

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.

cyu avatar cyu commented on July 23, 2024

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.

1updesign avatar 1updesign commented on July 23, 2024

Thanks GermanDZ

from rack-cors.

GermanDZ avatar GermanDZ commented on July 23, 2024

hey! @1updesign this is shocking… our company is called @1uptalent :)

from rack-cors.

amba178 avatar amba178 commented on July 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.