On a remote server, there is an HTML page with javascript. The user visits this page, makes some settings, and runs an API query.
How can I ensure that all API queries are routed independently from the user's location through a specific IP address, which is my proxy gateway? How is it possible with javascript?
This is the whole function that runs API query:
function Query(keyword)
{
var qk = keyword;
var queryresult = '';
queryflag = true;
$.ajax({
url: window.location.protocol + "//apiv3.example.com/lookup",
jsonp: "jsonp",
dataType: "jsonp",
data: {
q: qk,
client: "chrome",
hl: document.querySelector("select").value
},
success: function(res) {
var rL = res[1];
var i = 0;
for(i = 0; i < rL.length; i++)
{
var currents = CleanVal(rL[i]);
if(hashMapResults[currents] != 1)
{
hashMapResults[currents] = 1;
SaveLatest(CleanVal(rL[i]));
ktq[ktq.length] = currents;
var j = 0;
for(j = 0; j < 26; j++)
{
var chr = String.fromCharCode(97 + j);
var currentx = currents + ' ' + chr;
ktq[ktq.length] = currentx;
hashMapResults[currentx] = 1;
}
}
}
FilterAndDisplay();
var textarea = document.getElementById("input");
textarea.scrollTop = textarea.scrollHeight;
queryflag = false;
}
});
}
You can't control routing between the user and the endpoint.
If you want data to go through your server then the URL you pass to $.ajax needs to be that of your server.