I have a node server that pulls info from a php server and sends it over where it needs to be through a callback. Once or twice ad day the server gets stuck in an infinite loop and I think it's because I'm not properly handling the connection between the the php and node server. I posted my authentication code below. Anyone have any ideas?
exports.authenticate = function(request, callback) {
var https = require('https');
var options = {
hostname: 'www.mysite.com',
port: 443,
path: '/site/chatauth?id=' + request.sessionID,
method: 'GET',
};
var req = https.request(options, function(res) {
//console.log("statusCode: ", res.statusCode);
// console.log("headers: ", res.headers);
res.on('data', function(d) {
// process.stdout.write(d);
});
});
req.end();
req.on('response', function (response) {
var data = '';
response.setEncoding('utf8');
response.on('data', function(chunk) {
data += chunk;
});
// console.log (request.sessionID);
response.on('end', function() {
try {
callback(JSON.parse(data));
} catch(e) {
callback();
console.log("authentication failed");
}
});
});
};