Improved geolocation download

This commit is contained in:
vjrj 2017-11-30 19:38:07 +01:00
parent 6f5f094082
commit 8eb5f0cd4c
2 changed files with 12 additions and 5 deletions

1
.gitignore vendored
View file

@ -4,3 +4,4 @@ settings-staging.json
settings-production.json
settings-development.json
imports/ui/stylesheets/.sass-cache/
public/GeoLite2-City.mmdb.gz

View file

@ -2,16 +2,22 @@ import { Meteor } from 'meteor/meteor';
// https://atmospherejs.com/thebakery/ipgeocoder
Meteor.startup(function(){
IPGeocoder.load();
// TODO, download from time to time in :public/GeoLite2-City.mmdb.gz
// http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
IPGeocoder.load(Meteor.absoluteUrl() + 'GeoLite2-City.mmdb.gz');
// load() stored it in: /tmp/GeoLite2-City.mmdb
});
Meteor.methods({
geo: function() {
// https://stackoverflow.com/questions/14843232/how-to-get-the-user-ip-address-in-meteor-server/22657421#22657421
clientIP = this.connection.clientAddress;
console.log(clientIP);
var geoData = IPGeocoder.geocode('82.124.236.10');
console.log(JSON.stringify(geoData));
var clientIP = this.connection.clientAddress;
if (clientIP === '127.0.0.1') {
clientIP = '80.58.61.250' // Some Spain IP address
}
var geoData = IPGeocoder.geocode(clientIP);
console.log(geoData);
return geoData;
}
});