app.use((req, res, next) => { if (!isBot(req.headers['user-agent'])) { return next(); } render(req, res); });
app.get('/ping', function (req, res) { // The /ping url has been requested by a web scanning bot. // We don't want to count it as a visitor so we will ignore it if(isbot(req.headers['user-agent'])){ return res.send('Bad robot!'); } // var ip = req.ip; //this is from original code // console.log('IP', ip) // FreeGeoIP has a very simple api request('http://www.geoplugin.net/json.gp?ip=' + external_ip, function (e, r, body) { //use external_ip instead of ip try { var data = JSON.parse(body); console.log("\n\n\nDATA\n\n\n", data) } catch(e){ return; } if (!e && r.statusCode == 200) { if(data.geoplugin_countryName){ // Store the users in an object with their ip as a unique key users[external_ip]={ //change ip to external_ip timestamp : new Date(), latitude : data.geoplugin_latitude, longitude: data.geoplugin_longitude, country: data.geoplugin_countryName }; console.log("\n\n\nUSERS\n\n\n", users) } } if(e){ console.error(e); } }); res.send('Done'); });