Sha256: 9d96b02aeab66fab5fc3786efcc49e62751c0ecf0bc42d2d067d406b0b98f603
Contents?: true
Size: 1.12 KB
Versions: 1
Compression:
Stored size: 1.12 KB
Contents
module Crawlable class Rack def initialize(app) @app = app end def call(env) if using_heroku?(env) || true if file = Crawlable::Sitemap.find(env['REQUEST_PATH'], heroku_writable_directory) return sitemap(file) elsif file = Crawlable::Feed.find(env['REQUEST_PATH'], heroku_writable_directory) return feed(file) end end @app.call(env) end def sitemap(file) [200, { 'Cache-Control' => 'public, max-age=86400', 'Content-Length' => File.size(file).to_s, 'Content-Type' => 'text/xml' }, IO.read(file)] end def feed(file) [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 def using_heroku?(env) if env["HEROKU"].nil? if env["HEROKU_PORT"].nil? && ENV["HEROKU_TYPE"].nil? env["HEROKU"] = false else env["HEROKU"] = true end end env["HEROKU"] == true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
crawlable-0.0.1.8 | lib/crawlable/rack.rb |