prevent config from being cached but preserve offline capability

This commit is contained in:
schlagmichdoch 2023-11-09 00:25:40 +01:00
parent 9a2227c30f
commit 778d49e84b
2 changed files with 67 additions and 21 deletions

View file

@ -27,23 +27,38 @@ class ServerConnection {
}
_getConfig() {
console.log("Loading config...")
return new Promise((resolve, reject) => {
let xhr = new XMLHttpRequest();
xhr.open('GET', 'config', true);
xhr.addEventListener("load", () => {
if (xhr.status === 200) {
// Config received
let config = JSON.parse(xhr.responseText);
console.log("Config loaded:", config)
this._config = config;
Events.fire('config', config);
resolve()
} else if (xhr.status !== 200) {
// Handle errors
console.error('Error:', xhr.status, xhr.statusText);
reject();
} else if (xhr.status < 200 || xhr.status >= 300) {
retry(xhr);
}
})
xhr.addEventListener("error", _ => {
retry(xhr);
});
xhr.send();
function retry(request) {
setTimeout(function () {
openAndSend(request)
}, 1000)
}
function openAndSend() {
xhr.open('GET', 'config');
xhr.send();
}
openAndSend(xhr);
})
}