fix: show explicit API online/offline status in frontend

This commit is contained in:
Oliver 2026-02-15 13:47:25 +01:00
parent 703230fb86
commit e5324edddf
No known key found for this signature in database

View file

@ -76,6 +76,8 @@ function initialize() {
flushSignalQueue(); flushSignalQueue();
renderQueueStatus(); renderQueueStatus();
checkApiHealth();
setInterval(checkApiHealth, 30000);
} }
function ensureDeviceToken() { function ensureDeviceToken() {
@ -101,12 +103,25 @@ function saveJSON(key, value) {
} }
function updateNetworkStatus() { function updateNetworkStatus() {
networkStatusEl.textContent = navigator.onLine ? "Online" : "Offline"; networkStatusEl.textContent = navigator.onLine ? "Browser: Online" : "Browser: Offline";
} }
function onOnline() { function onOnline() {
updateNetworkStatus(); updateNetworkStatus();
flushSignalQueue(); flushSignalQueue();
checkApiHealth();
}
async function checkApiHealth() {
try {
const response = await fetch(`${API_BASE}/health`, { cache: "no-store" });
if (!response.ok) {
throw new Error("health_failed");
}
networkStatusEl.textContent = navigator.onLine ? "Browser: Online | API: Online" : "Browser: Offline | API: Online";
} catch {
networkStatusEl.textContent = navigator.onLine ? "Browser: Online | API: Offline" : "Browser: Offline | API: Offline";
}
} }
function renderQueueStatus() { function renderQueueStatus() {