mirror of
https://github.com/umami-software/umami.git
synced 2026-02-11 08:07:12 +01:00
Updated maxmind lookup.
This commit is contained in:
parent
444b828bc9
commit
88227b6b29
3 changed files with 9 additions and 9 deletions
|
|
@ -12,7 +12,7 @@ import {
|
|||
IP_ADDRESS_HEADERS,
|
||||
} from './constants';
|
||||
|
||||
let lookup;
|
||||
const MAXMIND = 'maxmind';
|
||||
|
||||
export function getIpAddress(headers: Headers) {
|
||||
const customHeader = process.env.CLIENT_IP_HEADER;
|
||||
|
|
@ -121,13 +121,13 @@ export async function getLocation(ip: string = '', headers: Headers) {
|
|||
}
|
||||
|
||||
// Database lookup
|
||||
if (!lookup) {
|
||||
if (!global[MAXMIND]) {
|
||||
const dir = path.join(process.cwd(), 'geo');
|
||||
|
||||
lookup = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
|
||||
global[MAXMIND] = await maxmind.open(path.resolve(dir, 'GeoLite2-City.mmdb'));
|
||||
}
|
||||
|
||||
const result = lookup.get(ip);
|
||||
const result = global[MAXMIND].get(ip);
|
||||
|
||||
if (result) {
|
||||
const country = result.country?.iso_code ?? result?.registered_country?.iso_code;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue