proxyweb/api.js
2025-10-27 07:57:59 -04:00

39 lines
1.1 KiB
JavaScript

var api = {
init: function (base_url) {
this.endpoint = base_url;
// console.log("API Init with base_url = " + base_url);
},
load_workers: function () {
console.log("load workers");
this.load_from_api("/1/workers", function (data, textStatus, jqXHR) {
console.log("Workers");
console.log(data);
});
},
load_status: function () {
console.log("load status");
this.load_from_api("/api.json", function (data, textStatus, jqXHR) {
console.log("Status");
console.log(data);
});
},
load_from_api: function (endpoint, callback) {
var headers = {};
headers.Authorization = "Bearer " + app_state.api_token;
const url = this.endpoint + endpoint;
$.ajax({
method: "get",
url: url,
headers: headers,
})
.done(function (data, textStatus, jqXHR) {
console.log("Endpoint " + endpoint + " result " + jqXHR.status);
callback(data, textStatus, jqXHR);
})
.fail(function (jqXHR, textStatus) {
console.log("Failed -> " + jqXHR.status + "/" + textStatus);
});
},
endpoint: null,
};