Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lessons/07-apis-debugging/ZG_twoter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
./node_modules
./oauth.js
8 changes: 4 additions & 4 deletions lessons/07-apis-debugging/ZG_twoter/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

Expand Down
16 changes: 16 additions & 0 deletions lessons/07-apis-debugging/ZG_twoter/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 {
Expand Down