Skip to content

Commit

Permalink
Merge pull request #23 from Master2022E/21-change-ip-get-call
Browse files Browse the repository at this point in the history
Location: Use the signal server endpoint to get ip and location infor…
  • Loading branch information
Thomsen96 authored Dec 19, 2022
2 parents ba0952e + e2c3b51 commit b88d5f4
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions src/components/Location.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,15 @@ const Location = () => {
const [ip, setIp] = useState("");
const [country, setCountry] = useState("");
const [regionName, setRegionName] = useState("");

const [city, setCity] = useState("");
const [isp, setIsp] = useState("");

const getIp = () => {
axios
.get("https://ifconfig.me/all.json")
.then((response) => {
setIp(response.data.ip_addr);
//console.log("got the IP address: ", response.data.ip_addr);
})
.catch(() => {
console.log("Could not get the IP.");
});
};

const getCountry = () => {
if (ip === "") return;
const signalUrl = process.env.REACT_APP_SIGNAL_URL;
axios
.get(signalUrl + "/ip/location/" + ip)
.get(signalUrl + "/ip/location")
.then((response) => {
setIp(response.data.ip);
setCountry(response.data.country);
setRegionName(response.data.regionName);
setCity(response.data.city);
Expand All @@ -38,8 +25,7 @@ const Location = () => {
});
};

useEffect(getIp, []);
useEffect(getCountry, [ip]);
useEffect(getCountry, []);

return (
<div style={{ color: "#000000" }}>
Expand Down

0 comments on commit b88d5f4

Please sign in to comment.