Permalink
Browse files

Added JSON endpoints to the /search and /wat routes. Switches based o…

…n the Accepts HTTP header.
  • Loading branch information...
1 parent bfda944 commit 093826ce1620970fef9823d6d00188ac69b639b7 @csainty csainty committed Apr 6, 2012
Showing with 3 additions and 0 deletions.
  1. +2 −0 routes/search.js
  2. +1 −0 routes/wat.js
View
2 routes/search.js
@@ -12,6 +12,8 @@ module.exports = function (req, res) {
.run(function (err, results) {
if (err) { return res.redirect('/error'); }
if (results.length === 0) { return res.redirect(url.format({ pathname: '/create', query: { phrase: req.query.q } })); }
+
+ if (req.accepts('json')) { return res.json(results); }
res.render('search', { title: 'say wat?', results: results, query: req.query.q });
});
};
View
1 routes/wat.js
@@ -13,6 +13,7 @@ module.exports = function (req, res) {
if (err) { return res.redirect('/error'); }
if (!wat) { return res.redirect('/'); }
+ if (req.accepts('json')) { return res.json(wat); }
res.render('wat', { title: 'say wat?', id: req.params.id, wat: wat });
});
};

0 comments on commit 093826c

Please sign in to comment.