Sinatra, Heroku and Superfeedr
This is a short tutorial on how to deploy an Sinatra web app that uses Superfeedr to Heroku. This app provides a very simple home page that lists the latests entries of some of your favorites sites. It’s greatly inspired by the awesome start.io from the awesome Peter Vidani and Jacob Bijani
Let’s start first by creating the application on Heroku.
Create the repo:
mkdir start-page && cd start-page
git add .
git commit -m "init"
Create the application on Heroku:
heroku create --stack cedar
Add the hostname as an environment variable. It is used by the rack middleware to build the callback urls:
heroku config:add HOST=<YOUR APP DOMAIN>
Add the superfeedr addon:
heroku addons:add superfeedr
This implementation is minimalistic, feel free to look at the code closely.
Let’s add the files:
mkdir views/ && touch views/index.erb
git add .
git commit -m "implemented" -a
That’s the simplest part:
First, let’s install the gems.
git add Gemfile.lock
git commit -m "adding Gemfile.lock" -a
And push the code
git push heroku master
… And that’s it!
Point your browser to your Heroku application. It is likely that you’ll have to wait for the feeds you have added to have new content before you see it appear on your home page. The last step is to make this page your default start page in your favorite web browser.
Heroku will put this application to sleep if you only use a single dyno… and since we store the entries in memory for now, that means you’ll lose that data if the app goes idle. The solution is very simple: store the data, using another Heroku addon!
Of course, this is a very simple application and there is a ton of little things that one can do to improve it:
- add the ability to dynamically subscribe to feeds
- show meta data, like the number of bit.ly clicks on each of the stories
- auto-refresh the page
The Superfeedr Heroku addon is still in alpha to this date, so if you want to run, this, please email us and we’ll get you in!
Liked this post? to get more or read the archive.