I'm making a little web app that has a queue on it, my entering queue code looks like so:
Angular:
$scope.leaveQueue = function() {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.post('/user/queue/leave')
.success(function(data) {
if (data.hasOwnProperty('success')) {
$route.reload();
return $scope.user.inQueue = false;
};
});
}
$scope.enterQueue = function() {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
$http.post('/user/queue/enter', $('#enterQueue').serialize())
.success(function(data) {
if (data.hasOwnProperty('success')) {
$route.reload();
return $scope.user.inQueue = true;
}
});
}
My backend with Node to handle said queues are like so:
router.route('/queue/enter')
.post(function(req, res, next) {
if (req.user.isLoggedIn) {
req.app.get('pg').connect(req.app.get('conString'), function(err, client, done) {
console.log(req.user.user_name, req.body.game, req.body.mode);
client.query("INSERT INTO queue (user_name, user_game, user_mode, created_on) VALUES ($1, $2, $3, $4)",
[req.user.user_name, req.body.game, req.body.mode, new Date()], function(err, results) {
if (err) { return res.json({'error': err}) };
return res.json({'success': 'Entered Queue Successfully'});
});
});
};
});
router.route('/queue/leave')
.post(function(req, res, nex) {
if (req.user.isLoggedIn) {
req.app.get('pg').connect(req.app.get('conString'), function(err, client, done) {
if (err) { return res.json({'error':err}) };
client.query("DELETE FROM queue WHERE user_name = $1", [req.user.user_name], function(err, results) {
if (err) { return res.json({ 'error': err}) };
return res.json({'success': results});
});
});
};
});
My problem is, if I enter and leave queue one too many times, my requests start to become infinitely pending
and won't resolve till I restart my node app.js
I have no idea why this is happening to me everything is returning a response wether there is an error or not so I'm not sure why it just leaves hanging and then works fine after a restart.
I'm not sure what is causing this, I'm new to Angular I'm not sure if I'm using $http
incorrectly. Any information AT ALL would be nice. Thank you.