Skip to content

Instantly share code, notes, and snippets.

@mwakipesile
Forked from ecto/home.js
Created July 28, 2016 01:30
Show Gist options
  • Save mwakipesile/c951eb25a192e3d0ff5f1fd7dc4e72f1 to your computer and use it in GitHub Desktop.
Save mwakipesile/c951eb25a192e3d0ff5f1fd7dc4e72f1 to your computer and use it in GitHub Desktop.
The home page for our FaceMash clone
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