Class: AppProfiler::Viewer::FirefoxRemoteViewer::Middleware

Inherits:
BaseMiddleware
  • Object
show all
Includes:
Yarn::WithFirefoxProfiler
Defined in:
lib/app_profiler/viewer/firefox_remote_viewer/middleware.rb

Instance Method Summary collapse

Methods included from Yarn::WithFirefoxProfiler

#setup_yarn, #valid_commands

Methods included from Yarn::Command

#setup_yarn, #valid_commands, #yarn, #yarn_setup, #yarn_setup=

Methods inherited from BaseMiddleware

id

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



12
13
14
15
16
17
# File 'lib/app_profiler/viewer/firefox_remote_viewer/middleware.rb', line 12

def initialize(app)
  super
  @firefox_profiler = Rack::File.new(
    File.join(AppProfiler.root, "node_modules/firefox-profiler/dist"),
  )
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/app_profiler/viewer/firefox_remote_viewer/middleware.rb', line 19

def call(env)
  request = Rack::Request.new(env)
  # Firefox profiler *really* doesn't like for /from-url/ to be at any other mount point
  # so with this enabled, we take over both /app_profiler and /from-url in the app in development.
  return from(env, Regexp.last_match(1))   if request.path_info =~ %r(\A/from-url/(.*)\z)
  return viewer(env, Regexp.last_match(1)) if request.path_info =~ %r(\A/app_profiler/firefox/viewer/(.*)\z)
  return show(env, Regexp.last_match(1))   if request.path_info =~ %r(\A/app_profiler/firefox/(.*)\z)

  super
end