我有以下代码,我试图将一些数据存储到会话变量:
//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();
}
});
未存储session.ipData。我可以将它存储在ip2location的调用之外,我可以在ip2location调用中获取会话数据。
任何想法: 谢谢
答案 0 :(得分:0)
我发现了问题。 next()回调需要在ip2Location调用中。