Skip to content

Instantly share code, notes, and snippets.

@clarkf
Created February 10, 2012 06:09
Show Gist options
  • Save clarkf/1787113 to your computer and use it in GitHub Desktop.
Save clarkf/1787113 to your computer and use it in GitHub Desktop.
DRY?
exports.whater = function (req, res) {
var format = req.params.format ? req.params.format : req.format;
User.findOne({ username: req.params.username }, function (err, doc) {
if (err) throw err;
if (!doc) {
if (format == 'json') {
res.json({ error: "no such user"});
} else {
res.render('404');
}
} else {
if (format == 'json') {
res.json(doc);
} else {
res.render('user/show', { user: doc });
}
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment