'Get JSON text from a online server

Ive been working on a site and it has a JS script that runs every 15 seconds which will go to a Github raw text site and get the data off that but I noticed it can be rate-limited.

function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
}

async function OnLaunch() {
    var i = 1
    while (i < 10) {
        const url = 'https://github.com/PS5Australia/stocktrackerau/blob/main/stock.json'
        var response = await fetch(url, {
            method: 'GET',
            headers: {
              Accept: 'application/json',
            }
          }
        )
        .then(response => response.text())
        .then(data => {
            var obj = JSON.parse(data);
            if (obj["AmazonDisc"] == "Out of Stock") {
                document.getElementById("amazondisc").innerHTML="Amazon | Out of Stock";
            }
            else if (obj["AmazonDisc"] == "In Stock") {
                document.getElementById("amazondisc").innerHTML="Amazon | In Stock";
            }
        });
        await sleep(15000);
    }
}

I have stock bots that will change the json, so is there another way of updating that json?

I am running on Azure but I can swap to AWS if need be.

Any help is appreciated, Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source