Rails heroku app帮助崩溃到许多重定向

时间:2012-04-01 13:13:07

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

我有这个第一个中间件:

class RedirectIt
require "net/https"
require "uri"
require 'open-uri'

  APP_DOMAIN = 'http://www.konkurrencerher.dk'
  def initialize(app)
    @app = app
  end
#
  def call(env)
    request = Rack::Request.new(env)
    if request.env['HTTP_HOST'] != APP_DOMAIN
        #REDIRECT TIL WWW
        [301, { "Location" => "#{APP_DOMAIN}#{request.fullpath()}"}, ["Redirecting..."]]
    elsif "#{request.fullpath()}".split(".").last == "png"
        #PROXY BILLEDER
        status, headers, response = @app.call(env)
        headers['Cache-Control'] = "public, max-age=#{84.hours.to_i}"
        headers['Content-Type'] = 'image/png'
        headers['Content-Disposition'] = 'inline'
        response_body = "#{(open('http://s3-eu-west-1.amazonaws.com/konkurrencerher#{request.path()}')).read}"
        [status, headers, response_body]
    else
      @app.call(env)
    end
 end

end

我的Heroku日志:http://pastie.org/private/wfhvsr2lqfmq9zknenx7q

1 个答案:

答案 0 :(得分:2)

HTTP_HOST只是裸主机名,没有协议(即www.konkurrencerher.dk),因此永远不会等于您的APP_DOMAIN常量,并且您将始终重定向。