Can't get rack-cors working in rails application

后端 未结 6 1258
野的像风
野的像风 2020-12-12 19:47

I wanted to implement CORS in my rails application, so I googled rack-cors gem for it. And I did everything as was said in README, that is updated Gemfile accordingly and up

6条回答
  •  遥遥无期
    2020-12-12 20:21

    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
    

提交回复
热议问题