2016-03-25 9 views
0

"Origin MYSITE.comはAccess Control-Allow-Originによって許可されていません。エラー。私は私のnginxでレール、ラック・コーラー、nginx、angualrjsおよびcors

namespace :api, defaults: {format: 'json'} do 
    scope module: :v1, constraints: ApiConstraints.new(version: 1, default: :true) do 
     resources :mailers do 
     collection do 
      post :subscribe 
      get :members 
     end 
     end 
     match '*path', via: [:options], to: lambda {|_| [204, {'Content-Type' => 'text/plain'}, []]} 
    end 
    end 

を持っている私のroutes.rbを中/ application.rb

config.middleware.insert_before 0, "Rack::Cors", :debug => true, :logger => (-> {Rails.logger }) do 
    allow do 
    origins(/http:\/\/localhost:(\d*)/, 
      /http:\/\/.*\.MYSITE\.com/, 
      /http:\/\/MYSITE\.com/, 
      ) 
    resource '*', 
     :headers => :any, 
     :methods => [:get, :post, :delete, :put, :options, :head, :patch], 
     :max_age => 0 
    end 
end 

私のconfigに

def subscribe 
    gibbon = Gibbon::Request.new 
    @list_id = 'some_id' 
    begin 
    resp = gibbon.lists(@list_id).members.create({body: subscribe_params}) 
    render json: {}, status: 200 
    rescue Gibbon::MailChimpError => e 
    render json: e.body, status: e.body['status'] 
    end 
end 

を持って私のコントローラで

> sites-有効> MYSITE.con

try_files $uri/index.html $uri @unicorn; 
    location @unicorn { 
    add_header 'Access-Control-Allow-Origin' '*'; 

    add_header X-Forwarded-For $proxy_add_x_forwarded_for; 
    add_header Host $http_host; 
    proxy_redirect off; 
    proxy_pass http://unicorn; 
    } 

答えて

1

同様の問題を抱えている人にとっては、nginx confの問題がありました。最初はadd_header 'Access-Control-Allow-Origin' '*';

を除去するために必要

Access-Control-Allow-Origin応答ヘッダがどこhttp://MYSITE, *として戻ってくることは無効であることに気づきませんでした。原点は1つだけです。

関連する問題