summaryrefslogtreecommitdiff
path: root/lib/router.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/router.js')
-rw-r--r--lib/router.js83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/router.js b/lib/router.js
new file mode 100644
index 0000000..d8e75c0
--- /dev/null
+++ b/lib/router.js
@@ -0,0 +1,83 @@
+var auth = require('./auth')
+var middleware = require('./middleware')
+var fortune = require('./fortune')
+var bucky = require('./bucky')
+
+module.exports = function(app){
+ app.all('*', middleware.ensureLocals)
+
+ auth.init()
+
+ app.get("/", middleware.ensureAuthenticated, function(req, res){
+ res.redirect('/index')
+ })
+ app.get("/login", function(req, res){
+ res.render("pages/login", {
+ title: "login"
+ })
+ })
+ app.get("/index", middleware.ensureAuthenticated, function(req, res){
+ res.render("pages/index", {
+ title: fortune("titles"),
+ hoot_text: fortune("hoots"),
+ })
+ })
+ app.get("/details/:id", middleware.ensureAuthenticated, function(req, res){
+ res.render("pages/details", {})
+ })
+
+ app.post("/api/login", auth.loggedInLocal)
+ app.get("/api/index",
+ bucky.ensureLatestThreads,
+ bucky.ensureCommentCountsForThreads,
+ bucky.ensureFileCountsForThreads,
+ bucky.ensureKeywordsForThreads,
+ bucky.ensureHootbox,
+ bucky.ensureLastlog,
+ function(req, res){
+ res.json({
+ threads: res.threads,
+ hootbox: res.hootbox,
+ lastlog: res.lastlog,
+ })
+ }
+ )
+ app.get("/api/thread/:id",
+ bucky.ensureThread,
+ bucky.ensureKeywordForThread,
+ bucky.ensureCommentsForThread,
+ bucky.ensureFilesForThread,
+ function(req, res){
+ res.json({
+ thread: res.thread,
+ comments: res.comments,
+ files: res.files,
+ keyword: res.keyword,
+ })
+ }
+ )
+ app.post("/api/thread/:id", function(req, res){
+ })
+ app.post("/api/thread/:id/comment", function(req, res){
+ })
+ app.delete("/api/thread/:id", function(req, res){
+ })
+
+ app.get("/api/keyword/:keyword",
+ bucky.ensureThreadsForKeyword,
+ bucky.ensureCommentCountsForThreads,
+ bucky.ensureFileCountsForThreads,
+ bucky.ensureKeywordsForThreads,
+ function(req, res){
+ res.json({
+ threads: res.threads,
+ })
+ }
+ )
+
+ app.put("/api/comment/:id", function(req, res){
+ })
+ app.delete("/api/comment/:id", function(req, res){
+ })
+
+}