feat(assist): fixed geoip race-condition

This commit is contained in:
Taha Yassine Kraiem 2022-04-14 18:17:08 +02:00
parent ffb82f38fc
commit 60cb0ea9b3
4 changed files with 11 additions and 7 deletions

View file

@ -268,9 +268,9 @@ function extractSessionInfo(socket) {
socket.handshake.query.sessionInfo.userDevice = ua.device.model || null;
socket.handshake.query.sessionInfo.userDeviceType = ua.device.type || 'desktop';
socket.handshake.query.sessionInfo.userCountry = null;
if (geoip !== null) {
if (geoip() !== null) {
debug && console.log(`looking for location of ${socket.handshake.headers['x-forwarded-for'] || socket.handshake.address}`);
let country = geoip.country(socket.handshake.headers['x-forwarded-for'] || socket.handshake.address);
let country = geoip().country(socket.handshake.headers['x-forwarded-for'] || socket.handshake.address);
socket.handshake.query.sessionInfo.userCountry = country.country.isoCode;
}
}

View file

@ -247,9 +247,9 @@ function extractSessionInfo(socket) {
socket.handshake.query.sessionInfo.userDevice = ua.device.model || null;
socket.handshake.query.sessionInfo.userDeviceType = ua.device.type || 'desktop';
socket.handshake.query.sessionInfo.userCountry = null;
if (geoip !== null) {
if (geoip() !== null) {
debug && console.log(`looking for location of ${socket.handshake.headers['x-forwarded-for'] || socket.handshake.address}`);
let country = geoip.country(socket.handshake.headers['x-forwarded-for'] || socket.handshake.address);
let country = geoip().country(socket.handshake.headers['x-forwarded-for'] || socket.handshake.address);
socket.handshake.query.sessionInfo.userCountry = country.country.isoCode;
}
}

View file

@ -218,9 +218,9 @@ function extractSessionInfo(socket) {
socket.handshake.query.sessionInfo.userDevice = ua.device.model || null;
socket.handshake.query.sessionInfo.userDeviceType = ua.device.type || 'desktop';
socket.handshake.query.sessionInfo.userCountry = null;
if (geoip !== null) {
if (geoip() !== null) {
debug && console.log(`looking for location of ${socket.handshake.headers['x-forwarded-for'] || socket.handshake.address}`);
let country = geoip.country(socket.handshake.headers['x-forwarded-for'] || socket.handshake.address);
let country = geoip().country(socket.handshake.headers['x-forwarded-for'] || socket.handshake.address);
socket.handshake.query.sessionInfo.userCountry = country.country.isoCode;
}
}

View file

@ -13,4 +13,8 @@ if (process.env.MAXMINDDB_FILE !== undefined) {
console.error("!!! please provide a valid value for MAXMINDDB_FILE env var.");
}
module.exports = {geoip}
module.exports = {
geoip: () => {
return geoip;
}
}