Class: MessageBus::Rack::Diagnostics
- Inherits:
-
Object
- Object
- MessageBus::Rack::Diagnostics
- Defined in:
- lib/message_bus/rack/diagnostics.rb
Overview
Accepts requests from clients interested in using diagnostics functionality
Instance Method Summary collapse
-
#call(env) ⇒ Object
Process an HTTP request from a subscriber client.
-
#initialize(app, config = {}) ⇒ Diagnostics
constructor
A new instance of Diagnostics.
Constructor Details
#initialize(app, config = {}) ⇒ Diagnostics
Returns a new instance of Diagnostics.
11 12 13 14 |
# File 'lib/message_bus/rack/diagnostics.rb', line 11 def initialize(app, config = {}) @app = app @bus = config[:message_bus] || MessageBus end |
Instance Method Details
#call(env) ⇒ Object
Process an HTTP request from a subscriber client
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/message_bus/rack/diagnostics.rb', line 18 def call(env) return @app.call(env) unless env['PATH_INFO'].start_with? "#{@bus.base_route}message-bus/_diagnostics" route = env['PATH_INFO'].split("#{@bus.base_route}message-bus/_diagnostics")[1] if @bus.is_admin_lookup.nil? || !@bus.is_admin_lookup.call(env) return [403, {}, ['not allowed']] end return index unless route if route == '/discover' user_id = @bus.user_id_lookup.call(env) @bus.publish('/_diagnostics/discover', user_id: user_id) return [200, {}, ['ok']] end if route =~ /^\/hup\// hostname, pid = route.split('/hup/')[1].split('/') @bus.publish('/_diagnostics/hup', hostname: hostname, pid: pid.to_i) return [200, {}, ['ok']] end asset = route.split('/assets/')[1] if asset && !asset !~ /\// content = asset_contents(asset) split = asset.split('.') return [200, { 'Content-Type' => 'application/javascript;charset=UTF-8' }, [content]] end [404, {}, ['not found']] end |