Heroku, Rails 4, and Rack::Cors

前端 未结 6 2064
既然无缘
既然无缘 2020-12-13 20:20

I am trying to use Rack::Cors with my Rails 4 application so that I can do a JSON based API.

CORS is in my Gemfile like this:

gem \'rack-cors\', :req         


        
6条回答
  •  庸人自扰
    2020-12-13 21:03

    I ran into the same problem with heroku. I found this blog with the same rack-cors issue.

    Just moved the use Rack::Cors to config.ru, redeployed to heroku and it works.

    require ::File.expand_path('../config/environment',  __FILE__)
    run Rails.application
    
    require 'rack/cors'
    use Rack::Cors do
    
      # allow all origins in development
      allow do
        origins '*'
        resource '*', 
            :headers => :any, 
            :methods => [:get, :post, :delete, :put, :options]
      end
    end
    

提交回复
热议问题