diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-09-03 18:31:54 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-09-03 18:31:54 -0400 |
| commit | df4892fb2b7abdbdc59ae7f9a7048b3fee1f9a07 (patch) | |
| tree | 02e61e3e40caa79de43e4d19ecf25c0c1c7fb304 /lib/index.js | |
| parent | c4f8d3508367de71f708825ccba48096f3490f1f (diff) | |
starting to write apis
Diffstat (limited to 'lib/index.js')
| -rw-r--r-- | lib/index.js | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/lib/index.js b/lib/index.js index 0489c77..20ccce5 100644 --- a/lib/index.js +++ b/lib/index.js @@ -17,6 +17,8 @@ var multer = require('multer') var db = require('./db') var auth = require('./auth') var middleware = require('./middleware') +var fortune = require('./fortune') +var bucky = require('./bucky') var app, server @@ -39,11 +41,11 @@ site.init = function(){ cookie: { domain: '.' + process.env.HOST_NAME, maxAge: 43200000000 }, store: sessionstore.createSessionStore({ type: 'mongodb', - host: 'localhost', // optional - port: 27017, // optional - dbName: 'sessionDb', // optional - collectionName: 'sessions',// optional - timeout: 10000 // optional + host: 'localhost', + port: 27017, + dbName: 'sessionDb', + collectionName: 'sessions', + timeout: 10000 }), resave: true, saveUninitialized: false, @@ -57,32 +59,47 @@ site.init = function(){ app.all('*', middleware.ensureLocals) server = http.createServer(app).listen(5000, function () { - console.log('Bucky listening at https://lvh.me:%s', server.address().port) + console.log('Bucky listening at http://5.k:%s', server.address().port) }) site.route() } site.route = function(){ - auth.init() app.get("/", middleware.ensureAuthenticated, function(req, res){ res.redirect('/index') }) app.get("/login", function(req, res){ - res.render("pages/login", {}) + res.render("pages/login", { title: "" }) }) app.get("/index", middleware.ensureAuthenticated, function(req, res){ - res.render("pages/index", {}) + res.render("pages/index", { title: fortune("titles") }) }) - app.post("/api/login", auth.loggedInLocal) - app.get("/api/index", function(req, res){ - }) - app.get("/api/thread", function(req, res){ - }) - app.post("/api/thread", function(req, res){ + app.get("/api/index", + bucky.ensureLatestThreads, + bucky.ensureCommentCountsForThreads, + bucky.ensureFileCountsForThreads, + function(req, res){ + res.json({ + threads: res.threads, + }) + } + ) + + app.get("/api/thread/:id", function(req, res){ + bucky.ensureThread, + bucky.ensureCommentsForThread, + bucky.ensureFilesForThread, + function(req, res){ + res.json({ + thread: res.thread, + comments: res.comments, + files: res.files, + }) + } }) app.post("/api/thread/:id", function(req, res){ }) |
