Making changes to app.rb
First, let's go to app.rb
and look at our list of required Gems:
require 'sinatra'
We're going to need two additional Gems, which are as follows:
json
: We'll use it to convert the JSON text inVCAP_SERVICES
into a data structuremysql2
: We'll use it to access the MySQL database
The expanded Gem requirements are as follows:
require 'sinatra' require 'json' require 'mysql2'
At the beginning of the application, we add new code that extracts MySQL credentials from the VCAP_SERVICES
. This environment variable contains a JSON string that parses into a data structure similar to this example:
{ "mysql-5.1"=>[ { "name"=>"insideaf-mysql", "label"=>"mysql-5.1", "plan"=>"free", "tags"=>["mysql", "mysql-5.1", "relational", "mysql-5.1", "mysql"], "credentials"=>{ "name"=>"d72374bco5g9u4s4f9e06e8e6014bdfdf", "hostname"=>"10.0.36.89", "host"=>"10.0.36.89", "port"=>3306, "user"=>...