Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…n the Accepts HTTP header.
  • Loading branch information...
commit 093826ce1620970fef9823d6d00188ac69b639b7 1 parent bfda944
Chris Sainty csainty authored
Showing with 3 additions and 0 deletions.
  1. +2 −0  routes/search.js
  2. +1 −0  routes/wat.js
2  routes/search.js
View
@@ -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 });
});
};
1  routes/wat.js
View
@@ -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 });
});
};
Please sign in to comment.
Something went wrong with that request. Please try again.