Modifying the application
We're going to change the application slightly. Instead of displaying a simple message, we're going to display a list of environment variables and their values. Here's the Ruby program that does this on the command line:
ENV.each do |name, value| value = value[0..19] + "..." if value.length > 20 print "#{name} = #{value}\n" end
This is a simple loop that iterates through the name/value pairs in the program's environment. Many environment variable values are extremely long, so we truncate those that are longer than 20 characters.
In the Sinatra version of the application, the same logic is divided between the following two files:
app.rb
, which contains the main Ruby source code.views/index.erb
, the ERB module that generates the page HTML.
Here's app.rb
as provided by AppFog:
require 'sinatra' set :protection, except: :ip_spoofing get '/' do erb :index end
The code we care about is contained in the last three lines. This specifies that an HTTP request to GET "...