Skip to content
Browse files

Merge pull request #13 from synedra/master

Provide needed pieces for Heroku
  • Loading branch information...
2 parents d3bebe8 + 9befdcf commit 1ad4751dc2dfd2c1e0f184c71a01fdb97ac6c1eb @mansilladev mansilladev committed
Showing with 21 additions and 14 deletions.
  1. +1 −0 Procfile
  2. +20 −14 app.js
View
1 Procfile
@@ -0,0 +1 @@
+web: node app.js
View
34 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) {
@@ -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);
+ config.redis.host = 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);
-}
+}

0 comments on commit 1ad4751

Please sign in to comment.
Something went wrong with that request. Please try again.