following problem: I am running an Nodejs server together with a mongoDB. By now I have always sent the results of my queries as json-data to the browser.
app.get('/gesamtergebnis', function(req,res){
User.aggregate([{$group: {
_id: "$Art",
Anzahl: {$sum: "$Anzahl"}
}
}], function(err,docs){
if(err){console.log(err);}
else {res.json(docs);}
});
});
My results are - what is the nature of those json responses - poorly formatted. So I have set up an html-file with a table ect. and a little ng-controller to get the data in the table with ng-repeat - no problem so far.
function AppCtrl($scope, $http) {
console.log("Hello from AppCtrl")
var showTotal = function(){
$http.get('./gesamtergebnis').success(function(response){
console.log("I got the data I requested!");
$scope.gesamtergebnis = response;
});
}
}
My routing is:
app.use(express.static(__dirname + "/public")); In the public folder is my index.html
My problem is: The index.html does not receive any server response;
I need to
- route a request to a certain html (res.sendfile does not helpt as I cannot add json data to the response) and
- send the json data from the mongodb request within the same route command
Is there no way to redirect the server response to a certain html (also other htmls then index) endpoint with data?
What is the best way to solve this? Get the routing done on the client side with Angular? How can I do this easily?
Any help would be great!
Hucho