Class: HTTPMe::Server

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Server

Returns a new instance of Server.



9
10
11
# File 'lib/httpme/server.rb', line 9

def initialize(options = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/httpme/server.rb', line 7

def options
  @options
end

Instance Method Details

#appObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

#runObject



13
14
15
16
17
18
19
20
21
# 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