(26 January, 2023 - 04:14 AM)ConfigShop Wrote: Show MoreSo Iv been thinking about converting my openbullet configs into a JavaScript api so for example domain.com/config/whatever_config but can’t figure out how proxies would be able to pass through it as most proxy providers my customers use are ip bounded so how would my customers be able to run the config through for example proxiware on my api.
As you explore the idea of converting your OpenBullet configs into a JavaScript API, you might be considering how to accommodate the use of proxies by your customers. Given that most proxy providers have IP-bound services, you might be wondering how to enable your API to run through such proxies.
Here's what you need to know: for your customers to use a proxy with your API, they must specify the proxy in the API request. With JavaScript and other programming languages, there are libraries available that enable you to specify a proxy in HTTP requests. This means that when the API request is made, it will pass through the specified proxy.
It's crucial to keep in mind that if your API is IP-bound and your customers use a proxy, the IP address of the request will be that of the proxy, not the customer. This could present issues if your API only accepts requests from specific IP addresses. In this scenario, you must update your API to accept requests from the IP addresses of your customers' proxy providers.
Code:
const axios = require('axios');
async function runConfig(configName, proxy) {
try {
const response = await axios.get(`https://your-api-domain.com/config/${configName}`, {
proxy: {
host: proxy.host,
port: proxy.port
}
});
return response.data;
} catch (error) {
console.error(error);
return error;
}
}
const proxy = {
host: 'proxy-host-name',
port: 8080
};
runConfig('whatever_config', proxy)
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});