Sha256: 12edefae6085390835dc302d2236dc468b146baba8f7c2b50110539908ab408d
Contents?: true
Size: 1.59 KB
Versions: 5
Compression:
Stored size: 1.59 KB
Contents
require 'sinatra/base' require 'rack' module Lurker class Server # fixed rack_contrib implementation class TryStatic def initialize(app, options) @app = app @try = ['', *options.delete(:try)] @static = ::Rack::Static.new( proc { [404, {}, []] }, # HERE proc, not lambda options) end def call(env) orig_path = env['PATH_INFO'] found = nil @try.each do |path| resp = @static.call(env.merge!('PATH_INFO' => orig_path + path)) break if 404 != resp[0] && found = resp end found or @app.call(env.merge!('PATH_INFO' => orig_path)) end end def self.to_rack(options = {}) default_path = options[:path] || Lurker::DEFAULT_SERVICE_PATH cls = Class.new(Sinatra::Base) do if !Rails.env.development? && (username, password = options.values_at(:username, :password)).all?(&:present?) use ::Rack::Auth::Basic, "Protected Area" do |u, p| username == u && password == p end end use ::Rack::Deflater use TryStatic, :root => "#{::Rails.root}/#{default_path}", # static files root dir :urls => %w[/], # match all requests :header_rules => [ [%w(css js), { 'Cache-Control' => 'public, max-age=31536000' }], [:fonts, { 'Access-Control-Allow-Origin' => '*' }] ], :try => ['.html', 'index.html', '/index.html'] # try these postfixes sequentially end Lurker.const_set("Rack_#{rand 10}_#{Time.now.to_i}", cls) cls end end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
lurker-0.6.6 | lib/lurker/server.rb |
lurker-0.6.5 | lib/lurker/server.rb |
lurker-0.6.4 | lib/lurker/server.rb |
lurker-0.6.3 | lib/lurker/server.rb |
lurker-0.6.2 | lib/lurker/server.rb |