Created
October 18, 2010 14:49
-
-
Save sivy/632325 to your computer and use it in GitHub Desktop.
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
// var favProvider = new FavProvider('localhost', 27017); | |
var favProvider = new FavProvider(); | |
var userProvider = new UserProvider(); | |
function loadUser(req, res, next) { | |
console.log('loadUser!'); | |
var name = 'sivy'; | |
// You would fetch your user from the db | |
userProvider.findByName(name, function(error, user){ | |
if (user) { | |
console.log(sys.inspect(user)); | |
req.user = user; | |
next(); | |
} else { | |
console.log('error!'); | |
next(new Error('Failed to load user ' + name)); | |
} | |
}); | |
} | |
// Routes | |
app.get('/', loadUser, function(req, res){ | |
console.log(sys.inspect(req.user)); | |
favProvider.findAll( function (error, faves) { | |
var ctx = { title: "Faves!", faves: faves }; | |
loader.load('index.html', function (error, t) { | |
t.render(ctx, function (error, result) { | |
res.send(result); | |
res.end(); | |
}); | |
}); | |
}); | |
}); |
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
# request to localhost:3000/ | |
loadUser! | |
{ username: 'sivy' | |
, password_hash: '098f6bcd4621d373cade4e832627b4f6' | |
, reminder: 'test' | |
, _id: 1 | |
, dateCreated: Mon, 18 Oct 2010 05:22:46 GMT | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment