An unoriginal web app that snaps screenshots of webpages and then displays the results.
Building A Rack Backend In 30 Minutes
Wherein Chris demonstrates the ease of building and deploying a small Rack-based app to Heroku.
This is RoboShot an unoriginal web app that snaps screenshots of webpages and then displays the results. I built him to experiment with PhantomJS's screenshot abilities.
Robo's parts list:
How's This Going To Work?
For this walk-through we will keep the front-end and throw away most everything else. We will then rebuild Robo's backend in three installments:
- Install gems, copy front-end, serve front-end
- PhantomJS & API
- Rack glue & deployment
After each section I will ask for questions, so please save any you may have till one of those breaks. Now would be one of those breaks.
Install Gems, Copy Front-end, Serve It
- Create Gemfile.
- Bundle it.
- cp front end (views & public dir)
- Show views/app.html briefly.
- Create app.rb.
- Demonstrate the page is served.
- Git init, git add ., git commit -m "first round."
PhantomJS & API
- cp PhantomJS (bin & phantom dirs)
- ls bin.
- ls Phantom dir
- cat phantom/phantom.rb
- cat phantom/script.js
- Create api.rb basic.
- Run api and curl basic.
- Add carrier wave logic.
- Run api and curl demo
- Git init, git add ., git commit -m "second round."
Rack glue & Deployment
- Create config.ru
- Heroku create
- git push heroku master
- Test it out.
Exercises For The Reader
- Add Unicorn for better concurrency.
- Add HTTP basic auth
- API throttling (a couple rack middle wares out there, but many are no longer actively maintained)
- Push the screenshot logic into workers. (although unicorn helps us quite a bit).
Code for RoboShot is on github at https://github.com/cacciatc/roboshot.
Thanks for listening. I'm Chris Cacciatore from Dullahan Software.