diff --git a/lessons/07-apis-debugging/ZG_twoter/.gitignore b/lessons/07-apis-debugging/ZG_twoter/.gitignore new file mode 100644 index 00000000..b628f24c --- /dev/null +++ b/lessons/07-apis-debugging/ZG_twoter/.gitignore @@ -0,0 +1,2 @@ +./node_modules +./oauth.js \ No newline at end of file diff --git a/lessons/07-apis-debugging/ZG_twoter/app.js b/lessons/07-apis-debugging/ZG_twoter/app.js index 18620dbd..f7765b47 100644 --- a/lessons/07-apis-debugging/ZG_twoter/app.js +++ b/lessons/07-apis-debugging/ZG_twoter/app.js @@ -69,7 +69,7 @@ app.get('/auth/facebook/callback', failureRedirect: '/login' }) ); -app.listen(3000); +app.listen(8000); //if the user is authenticated, then we can direct them to the home page, else we can go back to log in function ensureAuthenticated(req, res, next) { @@ -80,6 +80,6 @@ function ensureAuthenticated(req, res, next) { } } - - - +// I added this because your app was not being referenced correctly +// in /bin/www at line 16... +module.exports = app; \ No newline at end of file diff --git a/lessons/07-apis-debugging/ZG_twoter/public/javascripts/home.js b/lessons/07-apis-debugging/ZG_twoter/public/javascripts/home.js index c6a88886..063f4419 100644 --- a/lessons/07-apis-debugging/ZG_twoter/public/javascripts/home.js +++ b/lessons/07-apis-debugging/ZG_twoter/public/javascripts/home.js @@ -49,6 +49,7 @@ $("#twoteFeed").children("#" + $(".loggedInUser").attr("id")).each(function (ind //when a twote is deleted, we use the twoteId to find the parent li tag and we remove it from the feed var onDeleteTwoteSuccess = function(data, status){ + // Nice frontend removal, also good job on keeping all logs away from master/prod. $("#" + data.twoteId).parent().remove(); }; diff --git a/lessons/07-apis-debugging/ZG_twoter/routes/index.js b/lessons/07-apis-debugging/ZG_twoter/routes/index.js index d4966ca3..0c12e2b5 100644 --- a/lessons/07-apis-debugging/ZG_twoter/routes/index.js +++ b/lessons/07-apis-debugging/ZG_twoter/routes/index.js @@ -5,6 +5,21 @@ var Twote = require('../models/twoteModel.js'); var mongoose = require('mongoose'); var Schema = mongoose.Schema +// Nice API structure. You can also think of outputting our API methods as part of an object you can +// initialize here. For instance, you can set routes = {} and then define each method as routes.home = function(req, res){...} etc. +// As a result, instead of exporting every single method at lines 108-112, you can simply state module.exports = routes and you are done. +// And then in your app.js you can have your callbacks be index.home etc. LMK if you have questions on that. + +// Also, instead of repeting this error statements when (err), you define an ErrorHandler as follows: +// ErrorHandler method + +// function errorHandler(err, req, res, next) { +// res.status(500); +// res.render('error', { error: err }); +// } + +// This allows you simply call that everytime we don't have success. + //just renders the login page var logIn = function(req, res){ res.render('login'); @@ -17,6 +32,7 @@ var home = function(req, res){ var userObj = req.user; var dbUser = User.find({fbID: req.user.id}, function(err, user){ if (err){ + // i.e. errorHandler(err, req, res); res.send(err).status(500); console.log("Error: ", err); } else {