1
我有這個中間件這是第一:轟然許多Rails的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