Class: Pechkin::AppBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/pechkin/app/app_builder.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
# File 'lib/pechkin/app/app_builder.rb', line 5

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

  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
    use Pechkin::Auth::Middleware, auth_file: options.htpasswd if options.htpasswd
    use Prometheus::Middleware::Exporter, registry: prometheus

    run app
  end
end