Angular people, I'm having an issue with multiple concurrent REST calls (with Restangular) and I can't seem to find the reason, and I don't know if it's me doing a stupid mistake or the server set up wrong.
I'm trying to do two (but they could easily be more somewhere else in the app) GETs on different endpoints, like this:
(vm is the controller's ViewModel)
Code:
var stuff = Restangular.all('stuff');
var things = Restangular.all('things');
stuff.getList().then(function(list){
vm.stuff = list;
});
things.getList().then(function(list){
vm.things = list;
});
Locally, on a super simple static web server provided by
grunt-contrib-connect and calling some .json files, it all works perfectly fine.
When I try on the server (a JBoss server I know totally nothing about) though, it hangs while trying to process both requests. And I mean it literally: whenever I try it, the server just dies and I have to restart it before trying to send another REST call.
I tried reading the server's log, but it's so absurdly verbose that I quickly gave up.
Once though, I noticed it starts the database query of one of the GETs, but stops right in the middle of it (something like "SELECT * FROM stuff WHERE id =") and it doesn't show anything more after.
If I comment out any one of the two calls, it works fine.
So far, the only solution I came up with is to put the second request (possibly the slower one) inside the .then() of the first:
Code:
var stuff = Restangular.all('stuff');
var things = Restangular.all('things');
stuff.getList().then(function(list){
vm.stuff = list;
things.getList().then(function(list){
vm.things = list;
});
});
Seeing this working fine, made me wonder if I was getting my first approach totally wrong.
I mean, is sending multiple requests one after another a newbie mistake (I'm an Angular newbie but don't tell it to my boss)?
Should I have expected to see the server dying on me, or is it that the server sucks and I've just have to work around its suckiness?