Class: Pechkin::AppBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/app.rb

Overview

Application configurator and builder. This creates all needed middleware and stuff

Instance Method Summary collapse

Instance Method Details

#build(handler, options) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pechkin/app.rb', line 5

def build(handler, options)
  app = App.new
  app.handler = handler
  prometheus = Pechkin::PrometheusUtils.registry
  logger = create_logger(options.log_dir)

  Rack::Builder.app do
    use Rack::CommonLogger, logger
    use Rack::Deflater
    use Prometheus::Middleware::Collector, registry: prometheus
    # Add Auth check if found htpasswd file or it was excplicitly provided
    # See CLI class for configuration details
    if options.htpasswd
      use Pechkin::Auth::Middleware, auth_file: options.htpasswd
    end
    use Prometheus::Middleware::Exporter, registry: prometheus

    run app
  end
end