Improved geolocation download
This commit is contained in:
parent
6f5f094082
commit
8eb5f0cd4c
2 changed files with 12 additions and 5 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -4,3 +4,4 @@ settings-staging.json
|
||||||
settings-production.json
|
settings-production.json
|
||||||
settings-development.json
|
settings-development.json
|
||||||
imports/ui/stylesheets/.sass-cache/
|
imports/ui/stylesheets/.sass-cache/
|
||||||
|
public/GeoLite2-City.mmdb.gz
|
||||||
|
|
|
||||||
|
|
@ -2,16 +2,22 @@ import { Meteor } from 'meteor/meteor';
|
||||||
|
|
||||||
// https://atmospherejs.com/thebakery/ipgeocoder
|
// https://atmospherejs.com/thebakery/ipgeocoder
|
||||||
Meteor.startup(function(){
|
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({
|
Meteor.methods({
|
||||||
geo: function() {
|
geo: function() {
|
||||||
// https://stackoverflow.com/questions/14843232/how-to-get-the-user-ip-address-in-meteor-server/22657421#22657421
|
// https://stackoverflow.com/questions/14843232/how-to-get-the-user-ip-address-in-meteor-server/22657421#22657421
|
||||||
clientIP = this.connection.clientAddress;
|
var clientIP = this.connection.clientAddress;
|
||||||
console.log(clientIP);
|
|
||||||
var geoData = IPGeocoder.geocode('82.124.236.10');
|
if (clientIP === '127.0.0.1') {
|
||||||
console.log(JSON.stringify(geoData));
|
clientIP = '80.58.61.250' // Some Spain IP address
|
||||||
|
}
|
||||||
|
var geoData = IPGeocoder.geocode(clientIP);
|
||||||
|
console.log(geoData);
|
||||||
return geoData;
|
return geoData;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue