Skip to content

Commit 0547361

Browse files
committed
Use simple-get to fetch the current country instead of get-json
1 parent 07c2555 commit 0547361

File tree

3 files changed

+46
-39
lines changed

3 files changed

+46
-39
lines changed

package-lock.json

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
"telephone input"
2727
],
2828
"dependencies": {
29-
"get-json": "^1.0.0",
30-
"libphonenumber-js": "^1.7.18"
29+
"libphonenumber-js": "^1.7.18",
30+
"simple-get": "^3.0.3"
3131
},
3232
"devDependencies": {
3333
"babel-eslint": "^7.2.3",

src/assets/default-country.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import getJSON from 'get-json';
1+
const get = require('simple-get')
22

33
const getCountry = function () {
44
return new Promise((resolve, reject) => {
5-
getJSON('https://ipinfo.io/json', (error, response) => {
5+
get.concat('https://ip2c.org/s', (error, response, data) => {
6+
// Response: 1;CD;COD;COUNTRY
67
if (error) {
7-
reject(error);
8+
return reject(error);
89
}
9-
resolve(response && response.country);
10+
const result = (data || '').toString();
11+
12+
if (!result || result[0] !== '1') {
13+
return reject(new Error('unable to fetch the country'));
14+
}
15+
16+
return resolve(result.substr(2, 2));
1017
});
1118
});
1219
};

0 commit comments

Comments
 (0)