My brain is hurting again. I’ve spent a lot of today debugging server setup issues and getting in the middle of a debate about Rack vs Sinatra as a method of serving up Single Page Applications. In the middle of all this my server file went missing and made me look like an idiot, and I had to follow a trail of breadcrumbs in the shape of error messages which told me I hadn’t done a load of obvious things. Not bundling my Gemfile before pushing to Heroku, and trying to use a server without a config file spring to mind as moments I’d rather forget (but have immortalised in this blog for some reason anyway).

I’ve been using protractor for testing, and getting totally confused about what I’m meant to be stubbing and what I actually need to test. One of those days when you suddenly realise you’re trying to test that something is itself, and that maybe you’re overdoing it on the testing efforts.

In short, anything that could go wrong went wrong today.

Despite a multitude of setbacks, my little app is now finally on Heroku. It’s really not much to look at so far, but if you fancy dynamically searching Github using a funny little app I made, do feel free. Tomorrow will hopefully result in some more interesting data being presented and maybe some CSS so it looks like a real thing.

Here are some pointers for anyone deploying a simple Rack app:

• Make sure you’ve created a Gemfile including your source, Ruby version and the ‘rack’ gem
• Bundle it, otherwise you won’t have a Gemfile.lock
• Shove your index, js folder, css folder and anything else your app needs in a ‘public’ folder
• Move your bower_components directory to public/bower_components
• Create a .bowerrc file in the top level of your application, and add the following text to it: { “directory”: “public/bower_components” }
• Add a buildpack to your Heroku env variables like so: heroku config:add BUILDPACK_URL=git://github.com/qnyp/heroku-buildpack-ruby-bower.git#run-bower
• Make sure your node_components are .gitignored
• Make sure your config file looks something like this:

use Rack::Static,
  :urls => ["/images", "/js", "/css", '/bower_components'],
  :root => "public"

run lambda { |env|
  [
    200,
    {
      'Content-Type'  => 'text/html',
      'Cache-Control' => 'public, max-age=86400'
    },
    File.open('public/index.html', File::RDONLY)
  ]
}

• Note that you may need to amend the urls values array to include any other folders you need
• Your server will be looking at the root (public, in the example above) for additional files. Therefore you need to make sure the references at the top of your html file include a forward slash at the front <script src="/js/app.js"></script>
• Type heroku create nats-awesome-app
heroku push origin master
• Junebugs, for our github-profiles challenge, if you’re using an API access token you’ll need to remove it from the .gitignore list. This doesn’t seem like a very satisfactory solution, but we were unable to find a good way of supplying a secret token to the front end. The best we could do was branch the repo for the heroku push and push to heroku using git push heroku yourbranch:master. Do be aware that when switching between branches your .gitignored access token may disappear.

Nat x