I have the following code that i am trying to store some data to a session variable:
//Capture IP geo-location info if it hasn't been set for this session
app.all('*', function(req, res, next){
//Stuff to run once for each user session
if (!req.session.runOnce){
req.session.runOnce = true;
if (!req.session.ipinfo || 1){
//add user ip to sessions for use on who's online
//if we're localhost, give it an 8.8.8.8 IP just so we can test something
if (req.ip == '127.0.0.1'){ip = '8.8.8.8'; }else{ip = req.ip; }
ip2location(ip, config.ipinfodb.apiKey, function(error, data){
var ipData = JSON.parse(data);
req.session.ipData = ipData;
});
next();
}else{
next();
}
}else{
next();
}
});
The session.ipData is not being stored. I can store it outside of the call to ip2location, and I can get session data inside of the call to ip2location.
Any ideas: Thanks
I found the problem. The next() callback needs to be in the ip2Location call.