forked from cloudfoundry-community/cf-env
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathenv.rb
30 lines (28 loc) · 1019 Bytes
/
env.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
require 'rubygems'
require 'sinatra'
require 'json/pure'
get '/' do
puts "Current env keys: #{ENV.keys.sort.inspect}"
res = "<html><body style=\"margin:0px auto; width:80%; font-family:monospace\">"
res << "<head><title>Cloud Foundry Environment</title><meta name=\"viewport\" content=\"width=device-width\"></head>"
res << "<h2>Cloud Foundry Environment</h2>"
res << "<div><table>"
ENV.keys.sort.each do |key|
value = begin
"<pre>" + JSON.pretty_generate(JSON.parse(ENV[key])) + "</pre>"
rescue
ENV[key]
end
res << "<tr><td><strong>#{key}</strong></td><td>#{value}</tr>"
end
res << "</table></div>"
res << "<h2>HTTP Request Headers</h2>"
res << "<div><table>"
env.inject({}){|acc, (k,v)| acc[$1.downcase] = v if k =~ /^http_(.*)/i; acc}.sort.each do |k,v|
res << "<tr><td><strong>#{k}</strong></td><td>#{v}</tr>"
end
res << "</table></div></body></html>"
end
get '/some-error' do
$stderr.puts "This is an error log"
end