Class: Lurker::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/lurker/server.rb

Defined Under Namespace

Classes: TryStatic

Class Method Summary collapse

Class Method Details

.to_rack(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/lurker/server.rb', line 27

def self.to_rack(options = {})
  Rack::Builder.app do
    document_root = options[:path] || Lurker::DEFAULT_DOCUMENT_ROOT

    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}/#{document_root}",  # 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

     run Proc.new { |env|
       [404, { "Content-Type" => "text/html" }, ["File not lurked: #{env['PATH_INFO']}\n"]]
     }
  end
end