FE+BE: deviceDetials migration to graphQL endpoints

Signed-off-by: jokob-sk <jokob.sk@gmail.com>
This commit is contained in:
jokob-sk
2025-12-25 11:39:28 +11:00
parent d119708538
commit ee5de27413
4 changed files with 382 additions and 465 deletions

View File

@@ -416,9 +416,25 @@ async function renderSmallBoxes() {
showSpinner();
// Get data from the server
const response = await fetch(`php/server/devices.php?action=getServerDeviceData&mac=${getMac()}&period=${period}`);
const protocol = window.location.protocol.replace(':', '');
const host = window.location.hostname;
const apiToken = getSetting("API_TOKEN");
const port = getSetting("GRAPHQL_PORT"); // same port your Flask app runs on
const apiBase = `${protocol}://${host}:${port}`;
const url = `${apiBase}/device/${getMac()}?period=${encodeURIComponent(period)}`;
const response = await fetch(url, {
method: "GET",
headers: {
"Authorization": `Bearer ${apiToken}`,
"Content-Type": "application/json"
}
});
if (!response.ok) {
throw new Error(`Error fetching device data: ${response.statusText}`);
const text = await response.text();
throw new Error(`Error fetching device data: ${response.status} ${text}`);
}
const deviceData = await response.json();