-
-
Save mwakipesile/c951eb25a192e3d0ff5f1fd7dc4e72f1 to your computer and use it in GitHub Desktop.
The home page for our FaceMash clone
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.get('/', function(req, res){ | |
db.keys('image:*:location', function(err,keys){ | |
if (err) { throw err; } | |
var offense = keys[Math.floor(Math.random()*keys.length)]; | |
var defense = keys[Math.floor(Math.random()*keys.length)]; | |
if (defense == offense) { | |
defense = keys[Math.floor(Math.random()*keys.length)]; | |
} | |
db.mget('image:' + offense + ':location', 'image:' + offense + ':rating', | |
'image:' + defense + ':location', 'image:' + defense + ':rating', | |
function(err, reply){ | |
res.render('battle.ejs', { | |
locals: { | |
offense: offense, | |
defense: defense, | |
battle: reply | |
} | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment