From 3e9db7517b1bb1dc7247c4da8ed8fd448904b245 Mon Sep 17 00:00:00 2001 From: ip2location Date: Wed, 8 Nov 2023 14:50:57 +0800 Subject: [PATCH 1/2] Update location.js --- src/options/location.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/options/location.js b/src/options/location.js index 403e2434..3fba6d7e 100644 --- a/src/options/location.js +++ b/src/options/location.js @@ -38,7 +38,7 @@ export default { ipinfo: function() { return { // This service responds with JSON, so we simply need to parse it and return the country code - url: '//ipinfo.io', + url: '//ipinfo.io/json', headers: ['Accept: application/json'], callback: function(done, response) { try { @@ -77,6 +77,27 @@ export default { } }, + // This service requires an option to define `key`. Options are proived using objects or functions + ip2locationio: function () { + return { + // This service responds with JSON, so we simply need to parse it and return the country code + url: 'https://api.ip2location.io/?key={api_key}&format=json', + headers: ['Accept: application/json'], + callback: function (done, response) { + try { + const json = JSON.parse(response); + return json.error ? toError(json) : { + code: json.country_code + }; + } catch (err) { + return toError({ + error: 'Invalid response (' + err + ')' + }); + } + } + }; + }, + maxmind: function() { return { // This service responds with a JavaScript file which defines additional functionality. Once loaded, we must From b6f4fe3cf27883607965474fe37145f7b23eba52 Mon Sep 17 00:00:00 2001 From: ip2location Date: Wed, 8 Nov 2023 14:54:24 +0800 Subject: [PATCH 2/2] Update location.js --- src/options/location.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/options/location.js b/src/options/location.js index 3fba6d7e..e84dac97 100644 --- a/src/options/location.js +++ b/src/options/location.js @@ -38,7 +38,7 @@ export default { ipinfo: function() { return { // This service responds with JSON, so we simply need to parse it and return the country code - url: '//ipinfo.io/json', + url: '//ipinfo.io', headers: ['Accept: application/json'], callback: function(done, response) { try { @@ -78,6 +78,7 @@ export default { }, // This service requires an option to define `key`. Options are proived using objects or functions + // User can sign up for the free api key at here: https://www.ip2location.io/sign-up ip2locationio: function () { return { // This service responds with JSON, so we simply need to parse it and return the country code