2017-01-31 1 views
1

corsを有効にするためにRack-cors gemを使用しようとしています。問題は、非取得要求の場合、ヘッダーが存在しないGET要求に対してヘッダーが送信されることです。ラック:cors gemがGETリクエストのcorsヘッダーを設定していない

application.rb

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

何が間違っていますか?

答えて

0

私のために働いています。 application.rbで次の設定をしています

config.middleware.insert_before 0, "Rack::Cors" do 
    allow do 
    origins *Rails.application.secrets.cors_origins 
    resource '/posts', headers: :any, methods: [:get, :post, :options] 
    resource '/post', headers: :any, methods: [:post, :options] 
    end 
end 
+0

どのバージョンのrailsとrails-apiを使用していますか? –

+0

rails(4.2.6)、rails-api(0.4.0) –

+0

これはなぜ私にとってはうまくいかないのかわかりません。私はRails 3.2.13を使用していて、rails-apiを使用していません。 –

関連する問題