My '/messages' API is used to query mongodb for document with given 'hostname' and 'day'. When I test it with 'postman' I got correct response, array of objects. But when angular client used, it gives me empty array [], why?
Controller
apiSvc.post('/messages', {hostname: "XYZ", day: '1'})
.then(function (response) {
console.log(response.data);
});
SERVICE
.factory("apiSvc", function($http) {
return {
post: function(url,data) {
return $http.post(url,data);
},
}
})
ROUTER
router.post('/messages', function (req, res, next) {
console.log(req.body.hostname, req.body.day);
Message.find({day: req.body.day, hostname: req.body.hostname},
function(err, message) {
res.send(message);
});
});