class HTTPMe::Server

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/httpme/server.rb, line 9
def initialize(options = {})
  @options = options
end

Public Instance Methods

app() click to toggle source
# File lib/httpme/server.rb, line 23
def app
  path = options[:path] || '.'
  auth = options[:auth]
  zone = options[:zone] || 'Restricted Area'

  Rack::Builder.new do
    if auth
      use Rack::Auth::Basic, zone do |username, password|
        auth.split(':') == [username, password]
      end
    end

    use Rack::Static, urls: ["/"], root: path, cascade: true, index: 'index.html'
    use IndexRedirector, root: path
    run Rack::Directory.new(path)
  end
end
run() click to toggle source
# File lib/httpme/server.rb, line 13
def run
  Rack::Handler::Puma.run(app, **rack_options) do |server|
    # :nocov: - FIXME: Can we test this?
    [:INT, :TERM].each do |sig|
      trap(sig) { server.stop }
    end
    # :nocov:
  end
end

Private Instance Methods

rack_options() click to toggle source
# File lib/httpme/server.rb, line 43
def rack_options
  {
    Port: (options[:port] || '3000'),
    Host: (options[:host] || '0.0.0.0'),
  }
end