회사에서 외주로 준 코드에서 문제가 발생하였다.
원인이 무엇인고하고 봤더니, userip를 가져오는 부분이 있는데 해당 부분에서 에러가 발생하였다.
원인은 user ip 주소를 가져오는 방식에 유료라이브러리를 사용하였는데,
해당 사용시 갯수 제한에 걸린 것.
{
"error": true,
"reason": "RateLimited",
"message": "Visit https://ipapi.co/ratelimited/ for details"
}
제한이 걸려있으면 진짜 이렇게 온다.
https://ipapi.co/json/token 이렇게 구별하는 것 같은데, 무료일 경우 token이 필요없다.
찾아보니 무료인지는 모르는 것 1개와
https://geolocation-db.com/json/
https://geolocation-db.com/json/
geolocation-db.com
{
"country_code":"KR",
"country_name":"South Korea",
"city":"null",
"postal":null,
"latitude":1234567892,
"longitude":12467899,
"IPv4":"123456",
"state":"null"
}
Geolocation DB - Geographic location By IP Address
geolocation-db.com
https://api.ipify.org?format=json
무료인 api 1개가 나오더라.
{"ip":"98.207.254.136"}
관련 문서는 바로 아래에!
ipify - A Simple Public IP Address API
API Usage Using ipify is ridiculously simple. You have three options. You can get your public IP directly (in plain text), you can get your public IP in JSON format, or you can get your public IP information in JSONP format (useful for Javascript developer
www.ipify.org
무료 라이브러리만 썼으면 문제 없을 이슈였는데 아쉽더라.
유저의 ip를 가져오려면 서버단에서 가져오는 방식 밖에 없어 이런 방법을 적용한 것 같은데 아쉽던...
사용방법은 간단하다.
let res = axios.get('https://geolocation-db.com/');
console.log(res);
let res2 = axios.get('https://api.ipify.org?format=json');
console.log(res2);
// try, catch는 그냥 생략~
+++ https://geolocation-db.com/json/ 은 애드블락에 블락되어버려 호출이 되지 않음 +++
'취업 > React.JS' 카테고리의 다른 글
[React-select] cursor not-allowed 적용 (0) | 2023.05.31 |
---|---|
[React.js] tailwind.css 설치하기 (0) | 2023.04.26 |
[React] IFrame에 폼태그 전송하기. (0) | 2023.02.28 |
[React.JS] 리액트 하위 컴포넌트 함수 호출시 여러번 호출 이슈. (0) | 2023.01.27 |
[React.JS] 자식창에서 부모창 호출하기. (0) | 2023.01.26 |