Use local geo database instead of npm package.
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import path from 'path';
|
||||
import requestIp from 'request-ip';
|
||||
import { browserName, detectOS } from 'detect-browser';
|
||||
import isLocalhost from 'is-localhost-ip';
|
||||
import maxmind from 'maxmind';
|
||||
import geolite2 from 'geolite2-redist';
|
||||
import {
|
||||
DESKTOP_OS,
|
||||
MOBILE_OS,
|
||||
@@ -60,15 +60,11 @@ export async function getCountry(req, ip) {
|
||||
}
|
||||
|
||||
// Database lookup
|
||||
const lookup = await geolite2.open('GeoLite2-Country', path => {
|
||||
return maxmind.open(path);
|
||||
});
|
||||
const lookup = await maxmind.open(path.resolve(__dirname, '../geo/GeoLite2-Country.mmdb'));
|
||||
|
||||
const result = lookup.get(ip);
|
||||
|
||||
lookup.close();
|
||||
|
||||
return result.country.iso_code;
|
||||
return result?.country?.iso_code;
|
||||
}
|
||||
|
||||
export async function getClientInfo(req, { screen }) {
|
||||
|
||||
Reference in New Issue
Block a user