Skip to content

Commit

Permalink
trying to fix geolocation
Browse files Browse the repository at this point in the history
  • Loading branch information
andrioid committed Oct 14, 2024
1 parent e9dbed1 commit 00ca045
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/actions/hello/country.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ export async function getCountryFromIP(
const res = await fetch(`http://ip-api.com/json/${ipAddress}`);
const resJ = await res.json();
if (!resJ.country) {
console.warn(`[Geolocation] Received response, but no country`);
return;
}
console.log("country found", resJ.country);
return resJ.country;
} catch (_err) {
console.error(`[Geolocation] Failed for ${ipAddress}`);
Expand Down
4 changes: 4 additions & 0 deletions src/actions/hello/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export const hello = {
getCountry: defineAction({
handler: async (input, ctx) => {
let ip = getIPfromHeaders(ctx.request.headers);
//console.log("! getCountry", ip);
if (!ip) {
//ip = "193.4.194.2";
//ip = "77.75.80.174"; // dk
console.log("!!! No ip found for client (normal for dev)");
return;
}

Expand Down

0 comments on commit 00ca045

Please sign in to comment.