may i know why i keep getting html file as return from my angular factory ?
this is my backend route
function ensureAuthenticated(req, res, next) {
if (!req.headers.authorization) {
return res.status(401).send({ message: 'Please make sure your request has an Authorization header' });
}
var token = req.headers.authorization.split(' ')[1];
var payload = jwt.decode(token, config.TOKEN_SECRET);
if (payload.exp <= moment().unix()) {
return res.status(401).send({ message: 'Token has expired' });
}
req.user = payload.sub;
next();
}
app.get('/api/me', ensureAuthenticated, userHandler.getMe);
this is the getMe function calling from userHandler
this.getMe = function(req, res, next){
// retrieve data from database by using req.user as id
User.findById(req.user, function(err, user) {
res.send(user);
});
}
in my service.js( i have try debug in here by changing the route '/api/me' to some other route it still return status 200 when there's no such route exist in route on my back end.
app.factory('Account', function($http) {
return {
getProfile: function() {
return $http.get('/api/me');
},
updateProfile: function(profileData) {
return $http.put('/api/me', profileData);
}
};
});
in my controller
$scope.getProfile = function() {
Account.getProfile()
.success(function(data) {
$scope.user = data;
console.log(data) // this print out the html file
})
.error(function(error) {
alert("something is wrong when retriving your data");
});
};
$scope.getProfile();
console.log(data) give me this
in the network tab
can anyone help me with this ? may i know is there any method to debug this kind of problem ? thanks !