I'm writing a simple api endpoint to determine if my server is able to reach the internet. It works great, but after 5 requests (exactly 5, every time) the request hangs. Same thing happens when I switch Google to Hotmail.com, which makes me think that this is something on my end. Do I need to close the http.get requests? I was under the impression that this function closes the requests automatically.
// probably a poor assumption, but if Google is unreachable its generally safe to say that the server can't access the internet
// using this client side in the dashboard to enable/disable internet resources
app.get('/api/internetcheck', function(req, res) {
console.log("trying google...");
http.get("http://www.google.com", function(r){
console.log("Got status code!: " +r.statusCode.toString());
res.send(r.statusCode.toString());
res.end();
console.log("ended!");
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
});