0

Please helpme.

I use rack_cors gem but not resolved my problem

this is my code

application.rb

config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins 'localhost', 'http://example.com'
    resource '*', :headers => :any, :methods => [:get, :post, :options]
  end
end

this is the error

XMLHttpRequest cannot load https://example.com/video.vtt. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.

  • CORS error have been treated here a lot ; read http://stackoverflow.com/questions/10636611/how-does-access-control-allow-origin-header-work and http://stackoverflow.com/questions/7067966/how-to-allow-cors and http://stackoverflow.com/questions/5750696/how-to-get-a-cross-origin-resource-sharing-cors-post-request-working for a start – Jason Krs Jan 12 '17 at 19:01
  • Does not solve my problem – bryan zamora Jan 12 '17 at 19:24
  • Ok try this. You want to circumvent CORS errors so download google chrome webserver https://chrome.google.com/webstore/detail/web-server-for-chrome/ofhbbkphhbklhfoeikjpcbhemlocgigb?hl=en Once you have it installed it will be helpful.You link your application folder to that "web server" then you run your application from there....Il will help simulate client/server architecture to avoid CORS. Just for testing this may be sufficient (it was for me to test an Ajax application) – Jason Krs Jan 12 '17 at 19:41
  • In production I get the same error – bryan zamora Jan 12 '17 at 19:47
  • Do you have your front end and back end on different domain ? (if the app running on a domain distinct from the one where the back end program is running ? ) – Jason Krs Jan 12 '17 at 20:40

1 Answers1

0

Simply test Rails environment before setting allowed origins.

Florent Morin
  • 842
  • 1
  • 10
  • 13