class Lurker::Server

Public Class Methods

to_rack(options = {}) click to toggle source
# 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