64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/message_bus/rack/diagnostics.rb', line 64
def call(env)
return @app.call(env) unless env['PATH_INFO'].start_with? '/message-bus/_diagnostics'
route = env['PATH_INFO'].split('/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('.')
if split[1] == 'handlebars'
content = translate_handlebars(split[0], content)
end
return [200, { 'content-type' => 'text/javascript;' }, [content]]
end
return [404, {}, ['not found']]
end
|