The default terminal down the bottom has a tendency to crash, start a full screen terminal to get started.
Press alt + t to open a full sreen terminal
We're going to build a Sinatra application, because Cloud 9 is a
bit different to a normal environment we're going to need to use rackup
to start our server.
Sinatra is a rack application, to start a rack application we use the command rackup
rackup
config.ru not found
To start our server we need a configuration file, we'll leave it empty for now.
# config.ru
rackup
Missing run or map statement
We've created the config file, but rack doesn't know which app to run. Let's tell it to run IdeaBoxApp.
# config.ru
run IdeaBoxApp
rackup
Unitialized constant IdeaBoxApp
Still no good, looks like we need to create an application called IdeaBoxApp.
We're going to create a really simple Sinatra application to get started, let's create an app.rb file.
# app.rb
class IdeaBoxApp < Sinatra::Base
end
We also need to tell rack where to find that file
# config.ru
require './app'
run IdeaBoxApp
rackup
Uniitialized constant Sinatra
IdeaBoxApp relies on Sinara so we're going to need to create a Gemfile which specifies this dependency
# Gemfile
source 'https://rubygems.org'
gem 'sinatra', require: 'sinatra/base'
And rack needs to know to load the gems
# config.ru
require 'bundler'
Bundler.require
require './app'
run IdeaBoxApp
Now let's download those files with the bundle command.
bundle
rackup
Error: you may be using the wrong PORT & HOST for your server app
Because we're developing on Cloud9 we need to specify the server and port for the application.
rackup -p $PORT -o $IP
Let's visit the url to see our website.
We're so close, the server is running, but the application doesn't have any content, let's try adding a hello world.
# app.rb
class IdeaBoxApp < Sinatra::Base
get '/' do
'Hello, world!'
end
end
In order for the changes to work, you need to reboot your rack server.
Protip: You can end the server by press ctrl+c
Now it's time to save our work and update Github.
git status
You should have four unstaged files
git add Gemfile
git add Gemfile.lock
git add config.ru
git add app.rb
You can also add all file with git add -A
where -A means "all unstaged files
Now we need to commit this work with a message
git commit -m "Created IdeaBox app"
And we need to push all those changes back to Github (refered to as origin)
git push origin