Class: Philiprehberger::CircuitBoard::Rack::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/philiprehberger/circuit_board/middleware.rb

Overview

Rack middleware that exposes /health, /health/ready, and /health/live endpoints.

Constant Summary collapse

HEALTH_PATHS =
%w[/health /health/ready /health/live].freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.

Parameters:

  • app (#call)

    the Rack application



11
12
13
# File 'lib/philiprehberger/circuit_board/middleware.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Array

Returns Rack response.

Parameters:

  • env (Hash)

    Rack environment

Returns:

  • (Array)

    Rack response



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/philiprehberger/circuit_board/middleware.rb', line 17

def call(env)
  path = env['PATH_INFO']

  case path
  when '/health'
    health_response
  when '/health/ready'
    ready_response
  when '/health/live'
    live_response
  else
    @app.call(env)
  end
end