Class: Rollbar::Middleware::Js

Inherits:
Object
  • Object
show all
Includes:
RequestDataExtractor
Defined in:
lib/rollbar/middleware/js.rb

Overview

Middleware to inject the rollbar.js snippet into a 200 html response

Defined Under Namespace

Classes: SecureHeaders3To5, SecureHeaders6, SecureHeadersFalse, SecureHeadersResolver

Constant Summary collapse

JS_IS_INJECTED_KEY =
'rollbar.js_is_injected'.freeze
SNIPPET =
File.read(File.expand_path('../../../../data/rollbar.snippet.js',
__FILE__))

Constants included from RequestDataExtractor

RequestDataExtractor::ALLOWED_BODY_PARSEABLE_METHODS, RequestDataExtractor::ALLOWED_HEADERS_REGEX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RequestDataExtractor

#extract_person_data_from_controller, #extract_request_data_from_rack, #scrub_params, #scrub_url

Constructor Details

#initialize(app, config) ⇒ Js

Returns a new instance of Js.



19
20
21
22
# File 'lib/rollbar/middleware/js.rb', line 19

def initialize(app, config)
  @app = app
  @config = config
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



13
14
15
# File 'lib/rollbar/middleware/js.rb', line 13

def app
  @app
end

#configObject (readonly)

Returns the value of attribute config.



13
14
15
# File 'lib/rollbar/middleware/js.rb', line 13

def config
  @config
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/rollbar/middleware/js.rb', line 24

def call(env)
  app_result = app.call(env)

  begin
    return app_result unless add_js?(env, app_result[1])

    response_string = add_js(env, app_result[2])
    build_response(env, app_result, response_string)
  rescue StandardError => e
    Rollbar.log_error(
      "[Rollbar] Rollbar.js could not be added because #{e} exception"
    )

    app_result
  end
end