diff --git a/lib/request.js b/lib/request.js index b30a710d..e5527f7d 100644 --- a/lib/request.js +++ b/lib/request.js @@ -12,6 +12,8 @@ import { MOBILE_SCREEN_WIDTH, } from './constants'; +let lookup; + export function getIpAddress(req) { // Cloudflare if (req.headers['cf-connecting-ip']) { @@ -61,7 +63,9 @@ export async function getCountry(req, ip) { } // Database lookup - const lookup = await maxmind.open(path.resolve('./public/geo/GeoLite2-Country.mmdb')); + if (!lookup) { + lookup = await maxmind.open(path.resolve('./public/geo/GeoLite2-Country.mmdb')); + } const result = lookup.get(ip);