From 8eb5f0cd4cb8915ba4691cdb5e71067aed370cd7 Mon Sep 17 00:00:00 2001 From: vjrj Date: Thu, 30 Nov 2017 19:38:07 +0100 Subject: [PATCH] Improved geolocation download --- .gitignore | 1 + imports/startup/server/geolocation.js | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index a7f0228..f5538d2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ settings-staging.json settings-production.json settings-development.json imports/ui/stylesheets/.sass-cache/ +public/GeoLite2-City.mmdb.gz diff --git a/imports/startup/server/geolocation.js b/imports/startup/server/geolocation.js index d279953..bf18970 100644 --- a/imports/startup/server/geolocation.js +++ b/imports/startup/server/geolocation.js @@ -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; } });