Heroku上的Rails应用程序 - CORS问题

时间:2013-05-17 15:00:59

标签: json ruby-on-rails-3 heroku cors

我在Heroku上有一个Rails应用程序,具有以下配置:

module MyAppApi
  class Application < Rails::Application

    # other configs

    config.middleware.use Rack::Cors do
      allow do
        origins '*'
        resource '*', 
            :headers => :any, 
            :methods => [:get, :post, :delete, :put, :options]
      end
    end
  end
end

我的问题是任何请求都返回301状态。例如:

$ curl \
    -i -H 'Accept: application/json' \
    -H 'Content-Type: application/json' \
    -X OPTIONS 'http://myappapi.heroku.com/api/v1/resource.json'

HTTP/1.1 301 Moved Permanently
Server: nginx
Date: Fri, 17 May 2013 14:56:00 GMT
Content-Length: 0
Connection: keep-alive
Location: http://myappapi.heroku.com/api/v1/resource.json

GET,POST的响应相同。关于这里发生了什么的任何想法?提前谢谢。

1 个答案:

答案 0 :(得分:2)

您要求 .heroku.com域名。尝试请求“ .herokuapp.com”而不是

https://devcenter.heroku.com/articles/error-codes#h16-redirect-to-herokuappcom