Book Image

Implementing AppFog

Book Image

Implementing AppFog

Overview of this book

AppFog is the leading platform-as-a-service provider of PHP, Ruby, Node.js, and Java solutions. It is used by developers worldwide to deploy tens of thousands of applications. AppFog delivers a reliable, scalable, and fast platform for deploying applications in the cloud.This book is a hands-on guide that will walk you through creating and deploying applications to the cloud using AppFog, which will allow you to get your application deployed without the hassle of setting up servers.This book demonstrates how to use the AppFog service to build an application and have it running in the Cloud. It will walk you through the initial AppFog setup process and explain how to create your first application in minutes.You will also discover how to use services such as databases to make your applications more powerful. You will also learn how to create applications from scratch.You will find out everything you need to know to get an application running in the cloud for the first time.
Table of Contents (13 chapters)
Implementing AppFog
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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