Class: RailsAppVersion::AppInfoMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_app_version/app_info_middleware.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  version_header: "X-App-Version",
  environment_header: "X-App-Environment"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ AppInfoMiddleware

Returns a new instance of AppInfoMiddleware.



10
11
12
13
# File 'lib/rails_app_version/app_info_middleware.rb', line 10

def initialize(app, options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rails_app_version/app_info_middleware.rb', line 15

def call(env)
  # Call the next middleware in the chain first
  status, headers, response = @app.call(env)

  # Add our custom headers to the response
  headers[@options[:version_header]] = Rails.application.version.full
  headers[@options[:environment_header]] = Rails.application.env

  # Return the modified response
  [ status, headers, response ]
end