andrea2010
andrea2010

Reputation: 338

Rails. No 'Access-Control-Allow-Origin' header is present on the requested resource

Error: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Backund Ruby on Rails, Frond-end Angular 5.

application.rb

...
module Dkeeper
  class Application < Rails::Application
    config.middleware.use Rack::Cors do
      allow do
      origins '*'
      resource '*', headers: :any, methods: [:get, :post, :put, :patch, :delete, :options, :head]
    end
end
...

Upvotes: 2

Views: 2483

Answers (1)

Dan Hilton
Dan Hilton

Reputation: 199

Looks like you're missing insert_before 0 according to the docs

config.middleware.insert_before 0, Rack::Cors do
  allow do
    origins '*'
    resource '*', headers: :any, methods: [:get, :post, :options]
  end
end

Upvotes: 1

Related Questions