From 2e535d86c729efc2c561de3639e14627eae703de Mon Sep 17 00:00:00 2001 From: Nisarg Date: Mon, 11 Oct 2021 10:38:05 -0700 Subject: [PATCH] maybe geoip is an array --- lib/request.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/lib/request.js b/lib/request.js index e944fb35..f88d6b54 100644 --- a/lib/request.js +++ b/lib/request.js @@ -61,12 +61,19 @@ export async function getLocation(req, ip) { const result = await geoip.lookup(ip); console.log(result); - - return { - country: result?.country, - region: result?.region, - city: result?.city, - }; + if (Array.isArray(result)) { + return { + country: result[0]?.country, + region: result[0]?.region, + city: result[0]?.city, + }; + } else { + return { + country: result?.country, + region: result?.region, + city: result?.city, + }; + } } export async function getClientInfo(req, { screen }) {