feat: prove the Wi-Fi, LittleFS, and HTTP vertical slice
This commit is contained in:
+32
@@ -0,0 +1,32 @@
|
||||
(() => {
|
||||
const target = document.querySelector('#health');
|
||||
const labels = {
|
||||
uptime_ms: 'Время работы (мс)', wifi_state: 'Wi-Fi', rssi_dbm: 'RSSI (дБм)',
|
||||
free_heap_bytes: 'Свободная память (байт)', min_free_heap_bytes: 'Мин. свободная память (байт)',
|
||||
build_version: 'Версия сборки'
|
||||
};
|
||||
|
||||
function render(health) {
|
||||
target.replaceChildren();
|
||||
for (const [key, label] of Object.entries(labels)) {
|
||||
const term = document.createElement('dt');
|
||||
const value = document.createElement('dd');
|
||||
term.textContent = label;
|
||||
value.textContent = health[key] ?? 'недоступно';
|
||||
target.append(term, value);
|
||||
}
|
||||
}
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
const response = await fetch('/api/health', { cache: 'no-store' });
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
render(await response.json());
|
||||
} catch (error) {
|
||||
target.textContent = `Не удалось получить состояние: ${error.message}`;
|
||||
}
|
||||
}
|
||||
|
||||
refresh();
|
||||
window.setInterval(refresh, 5000);
|
||||
})();
|
||||
Reference in New Issue
Block a user