module Crawlable class Rack def initialize(app) @app = app end def call(env) if ENV["HEROKU"] return sitmap if env['REQUEST_PATH'] =~ /\/sitemap\.xml/i end @app.call(env) end def sitemap file = File.join(heroku_writable_directory, "sitemap.xml.gz") [200, { 'Cache-Control' => 'public, max-age=86400', 'Content-Length' => File.size(file).to_s, 'Content-Type' => 'text/xml' }, IO.read(file)] end def heroku_writable_directory "#{Rails.root}/tmp" end end end