require 'rack/cors'
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins CORS_ORIGINS[Rails.env]
resource '*', :headers => :any, :methods => [:get, :post, :options, :put, :delete],credentials: true
end
end
I'm using gem 'rack-cors' This was worked fine for my different project but currently in ruby '2.7.6', rails '5.1.7' I'm facing some issue, I'm not sure is this because of the version of ruby on rails or else.
/config/initializers/cors.rb
as mentioned in gem 'rack-cors', code written in above file, also tried in config.ru, later tried in /config/application.rb
I'm printing some message like,
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
puts "************cors************"
origins CORS_ORIGINS[Rails.env]
resource '*', :headers => :any, :methods => [:get, :post, :options, :put, :delete],credentials: true
end
end
This message is also printing in above cases but when deploying on server, this is not working.
I have an almost similar environment and have a working CORS Management. Maybe this helps. I Sort out origins fesert, then putting Resource.