summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-09-07 14:04:18 -0400
committerJules Laplace <jules@okfoc.us>2015-09-07 14:04:18 -0400
commitebac7f79d32c524de750adc3bcf1cc539625d552 (patch)
tree0967200ce631c16a54121d36a3e472eb08ad049c /lib
parentaa9718404cba9cf1c872b7cedded31d68d3beb54 (diff)
split up partials and stub in mailbox frontend
Diffstat (limited to 'lib')
-rw-r--r--lib/bucky.js13
-rw-r--r--lib/router.js2
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/bucky.js b/lib/bucky.js
index a429fb3..997d680 100644
--- a/lib/bucky.js
+++ b/lib/bucky.js
@@ -103,6 +103,19 @@ var bucky = module.exports = {
/* KEYWORDS */
+ ensureKeyword: function (req, res, next){
+ var keyword = req.params.keyword
+ if (! keyword) {
+ res.sendStatus(404)
+ }
+ db.getKeyword(keyword).then(function(k){
+ if (! k) {
+ return res.sendStatus(404)
+ }
+ res.keyword = k
+ next()
+ })
+ },
ensureThreadsForKeyword: function (req, res, next){
var keyword = req.params.keyword
if (! keyword) {
diff --git a/lib/router.js b/lib/router.js
index d8e75c0..92c0054 100644
--- a/lib/router.js
+++ b/lib/router.js
@@ -64,12 +64,14 @@ module.exports = function(app){
})
app.get("/api/keyword/:keyword",
+ bucky.ensureKeyword,
bucky.ensureThreadsForKeyword,
bucky.ensureCommentCountsForThreads,
bucky.ensureFileCountsForThreads,
bucky.ensureKeywordsForThreads,
function(req, res){
res.json({
+ keyword: res.keyword,
threads: res.threads,
})
}