Sha256: f6ba80efa1413e906b448acbb7271ae284d661ec2b2c27c364a939211ee01ae2

Contents?: true

Size: 570 Bytes

Versions: 2

Compression:

Stored size: 570 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
crawlable-0.0.1.7 lib/crawlable/rack.rb
crawlable-0.0.1.6 lib/crawlable/rack.rb