From 321358c89d31f1ebf492867f30eff038a8099295 Mon Sep 17 00:00:00 2001 From: Kirsten Jones Date: Fri, 6 Jan 2012 15:48:28 -0800 Subject: [PATCH] Fixing app.js to allow for heroku. Also adding config.json for heroku test (will remove after) --- app.js | 27 +++++++++++++-------------- config.json | 12 ++++++++++++ 2 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 config.json diff --git a/app.js b/app.js index 82dec80c..3bccf15e 100755 --- a/app.js +++ b/app.js @@ -49,18 +49,16 @@ try { // Redis connection // var defaultDB = '0'; -var db = redis.createClient(config.redis.port, config.redis.host); -db.auth(config.redis.password); - -// Select our DB -db.on("connect", function() { - db.select(defaultDB); - 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, config.redis.host); + db.auth(config.redis.password); +} db.on("error", function(err) { if (config.debug) { @@ -651,6 +649,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); -} +} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 00000000..107ad047 --- /dev/null +++ b/config.json @@ -0,0 +1,12 @@ +{ + "title" : "I/O Docs - http://github.com/mashery/iodocs", + "port" : 3000, + "debug" : true, + "sessionSecret" : "12345", + "redis" : { + "host" : "localhost", + "port" : 6379, + "password" : "", + "database" : "0" + } +}