This is about a problem in posting angularjs to express 4.0
I followed a course on pluralsight on MEAN stack. I got the source code from github of the course teacher (https://github.com/joeeames/multivision-demo). You can find the line of code here: https://github.com/joeeames/multivision-demo/blob/master/public/app/account/mvAuth.js
authenticateUser: function(username, password) {
var dfd = $q.defer();
$http.post('/login', {username:username, password:password}).then(function(response) {
if(response.data.success) {
var user = new mvUser();
angular.extend(user, response.data.user);
mvIdentity.currentUser = user;
dfd.resolve(true);
} else {
dfd.resolve(false);
}
});
return dfd.promise;
},
now if you node/bower install the project as-is, you get all working ok (in package.json you see "express": "~3.4.4"). If you update it to Express 4.0 and provide requirements of express 4.0 like having separated body-parser, cookie-parser, etc. it will have a problem: if you try to login, the above lines will generate error (400 bad request, from Angularjs to Passport.authenticate()). After upgrading to express 4.0 my LocalStrategy of passport will never get called. Unfortunately, I don't have enough knowledge to use something like wireshark or other tools to check detail of http between posting to hopefully find it out. Could anyone please give an idea, how to having it working after upgrading to express 4.0 please?
This alone won't help. You need to specify the Content-Type for the body parser:
app.use(bodyParser.json({ type: 'application/*+json' }))
and ensure the client is using that Content-Type, which in your case is okay.
I know this is an old question but I thought I would post a response since I ran into something similar. I upgraded a REST api to express 4 and then my Angular interface would not post to it. The problem was not with angular but the parsing of the POST data. Angular by default posts data as JSON so I needed to add the following to make sure my express app could parse the JSON.
app.use(bodyParser.json());