Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Implementing AppFog

You're reading from   Implementing AppFog Getting to grips with the AppFog service is easily achieved with this hands-on guide, which walks you through creating and deploying applications to the cloud. You'll be developing your first application in minutes.

Arrow left icon
Product type Paperback
Published in Nov 2013
Publisher Packt
ISBN-13 9781849698184
Length 86 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

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 "...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image