Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Provide needed pieces for Heroku #13

merged 4 commits into from

3 participants


To test on normal system, just run it. Should be no differences.

For heroku, get heroku setup as defined here:

Copy config.json.sample to config.json

Before you deploy to heroku, config.json needs to be in the repository, so you can git init the directory so it's no longer tied to the iodocs master stuff, or just add it and delete it later. Pull a clone of my repo if you want :-)

So either (reset your repo):
% git init
% git add .
% git add -f config.json
% git commit -m "init"

or (update the current one):
git add config.json
git commit -a

% heroku create --stack cedar;
% heroku addons:add redistogo
% heroku addons:add logging
% git push heroku master
% heroku ps:scale web=1

This'll should get you a working app at

@mansilladev mansilladev merged commit 1ad4751 into mashery:master

Why would you add this code again here when you perform the same logic check and variable assignment a few lines above for the redis connection? Wouldn't it be cleaner to piggyback the config object earlier in the code so you don't add so many hooks for Heroku?

Sure, you could do that. I'm sure if you wanted to fork and make a cleanup pull request Neil would be happy to take it :-)

Fair enough. I'll have to beef up on my Git skills before I can do that. Which was one of my geek 2012 resolutions anyway.

Sounds good. If I have occasion to pull another branch for another change (there are a few on my list) I'll make sure to catch this as well.


Why was this block removed? I'm learning though this project and additional clarity would be appreciated. I see it works with or without it. In which case, why did it exist in the first place?

I think it was older code from a previous version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 14 deletions.
  1. +1 −0  Procfile
  2. +20 −14 app.js
1  Procfile
@@ -0,0 +1 @@
+web: node app.js
34 app.js
@@ -49,18 +49,16 @@ try {
// Redis connection
var defaultDB = '0';
-var db = redis.createClient(config.redis.port,;
-// Select our DB
-db.on("connect", function() {
- db.get("livedocs", function(err, reply) {
- if (config.debug) {
- console.log('Selected db \''+ defaultDB + '\' named \'' + reply + '\'');
- }
- });
+var db;
+if (process.env.REDISTOGO_URL) {
+ var rtg = require("url").parse(process.env.REDISTOGO_URL);
+ db = require("redis").createClient(rtg.port, rtg.hostname);
+ db.auth(rtg.auth.split(":")[1]);
+} else {
+ db = redis.createClient(config.redis.port,;
+ db.auth(config.redis.password);
db.on("error", function(err) {
if (config.debug) {
@@ -82,6 +80,13 @@ fs.readFile('public/data/apiconfig.json', 'utf-8', function(err, data) {
var app = module.exports = express.createServer();
+if (process.env.REDISTOGO_URL) {
+ var rtg = require("url").parse(process.env.REDISTOGO_URL);
+ = rtg.hostname;
+ config.redis.port = rtg.port;
+ config.redis.password = rtg.auth.split(":")[1];
app.configure(function() {
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
@@ -651,6 +656,7 @@ app.get('/:api([^\.]+)', function(req, res) {
// Only listen on $ node app.js
if (!module.parent) {
- app.listen(config.port, config.address);
+ var port = process.env.PORT || config.port;
+ app.listen(port);
console.log("Express server listening on port %d", app.address().port);
Something went wrong with that request. Please try again.