【发布时间】:2015-03-14 03:53:48
【问题描述】:
我将 MEAN 堆栈用于app,我有用户使用satellizer 注册和登录,一切正常。
但是当我尝试通过它的 ID get 用户时,我什么也得不到,我可以请求获取所有用户,但不能通过 ID。
注意我使用 Ionicframework 作为 forntEnd 框架。 这是我的后端端点的代码:
app.get('/api/me', function(req, res) {
User.findById(req.user, function(err, user) {
console.log(req.user);
console.log(user);
res.send(user);
});
})
我的前端代码控制器:
.controller('ProfileCtrl', function($scope, $http, $stateParams, $ionicLoading, $timeout, $stateParams) {
$ionicLoading.show({
template: 'Loading...'
});
$http.get('http://localhost:3000/api/me')
.success(function(data) {
console.log("Recived data via HTTP", data);
$timeout(function() {
$ionicLoading.hide();
$scope.user = data;
}, 1000);
})
.error(function() {
console.log("Error while getting the data");
$ionicLoading.hide();
});
})
请求标头:
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8,ar;q=0.6,fi;q=0.4,it;q=0.2,en-GB;q=0.2,en-CA;q=0.2
Authorization:Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiI1NTAxYjAxMmExMjRlZjIwMTc4M2ExMTQiLCJleHAiOjE0MjcxMzk0NDV9.x9QEdE4E-Vh1SklCheiZqsnJsg8jGzdJnPx2RXeZqS8
Connection:keep-alive
Host:localhost:3000
Origin:http://localhost:8100
Referer:http://localhost:8100/
【问题讨论】:
-
req.user在User.findById调用之前的值是多少?
标签: angularjs node.js mongodb http ionic-framework