by

Geddy on OpenShift

Updated 2014/03/20: Added disableBuild to prevent restarts.

Remember those days where JavaScript were those snippets of buggy code sitting in HTML pages? Well, those days are over.. JavaScript is hot! It’s what I write 100% native mobile apps in, most of Titanium tools themselves are written in it and with Ti.Next (Titanium 4.0) even the compiler and the API will be all JavaScript. Thanks to NodeJS, JavaScript quickly became a full-stack solution.

Geddy

So, after having done a CLI in NodeJS, I felt for this new project I’m doing I might as well try doing a back-end in it. After spending some time with plain Express and Sails, I ended up using the Geddy framework for this. The framework has been out there since the early days of NodeJS (2010) and features great documentation and (community) support.

Geddy + OpenShift

I hosted my previous back-ends on a private PHP server. Since Appcelerator has good connections with Red Hat’s OpenShift, I decided to use their NodeJS server. I didn’t find an official guide on how to use Geddy on OpenShift, but it was relatively easy to figure out so here you are:

Set up OpenShift

  1. Create a free account at Redhat OpenShift
  2. Add an application using the NodeJS 0.10 cartridge.
  3. Follow the instructions to clone the repository, but don’t commit anything just yet.
  4. On your application’s dashboard, also add the MongoDB 2.2 cartridge to your app.

Set up Geddy

On your local machine:

  1. Install Geddy globally:
    $ [sudo] npm install -g geddy
  2. Change to the folder under which you want Geddy to create another folder with your app. Make sure Geddy will not overwrite the cloned repository!
  3. Generate an Geddy app:
    $ geddy gen app <name>
  4. Copy the contents of the Geddy app to the cloned repository:
    $ cp -a <name>/ <clone>/
  5. Delete the Geddy app:
    $ rm -rf <name>

Configure Geddy

In the repository folder:

  1. Generate a secret for sessions and so on:
    $ geddy gen secret
  2. Open config/secrets.json and make the following change:
    Replace YoUrSeCrEt with whatever secret was generated. This will only be used on your local machine. When deployed to OpenShift, their shared secret token will be used so your live key will not be in revision control, which would not be secure.
  3. Open .gitignore and remove the following line:
    This will make sure the file will be deployed to OpenShift.
  4. Open package.json and make the following changes:
    Geddy is not available globally OpenShift so we require a local one. Until 0.12.8 or later gets released, we need to fetch the master from GitHub to be able to use disableBuild later on. Mongo is globally available, but Geddy requires it local. We need mongodb-wrapper for storing sessions in a Mongo DB. The engines configuration is the default for a NodeJS cartridge.
  5. Open server.js and replace the contents with:
    On your local machine you would use the geddy CLI command to start the server, so the fallbacks to local ports and hostname are not required, but there so you can test it locally.
  6. Open config/production.js and make the following changes:
    On OpenShift you cannot store the sessions on disk, so we use Mongo. Please note that the property names are not 100% identical to db. The disableBuild is a new option I’ve added that will prevent Geddy from generating new helpers and models in the public directory. Because OpenShift uses supervisor, this would trigger an endless loop of restarts.

Deploy to OpenShift

  1. Add files:
    $ git add .
  2. Commit changes:
    $ git commit -am "Added Geddy"
  3. Push to OpenShift:
    $ git push
  4. Open the application in your browser.