feat: Add initial Svelte frontend for ESP32 system monitoring and reboot control.
This commit is contained in:
35
Provider/frontend/src/lib/api.js
Normal file
35
Provider/frontend/src/lib/api.js
Normal file
@@ -0,0 +1,35 @@
|
||||
/**
|
||||
* API layer for Calendink Provider ESP32-S3 dashboard.
|
||||
*
|
||||
* VITE_API_BASE controls the backend URL:
|
||||
* - Development (PC): "http://<ESP32_IP>" (set in .env.development)
|
||||
* - Production (ESP32): "" (empty = relative URLs, same origin)
|
||||
*/
|
||||
|
||||
const API_BASE = import.meta.env.VITE_API_BASE || '';
|
||||
|
||||
/**
|
||||
* Fetch system information from the ESP32.
|
||||
* @returns {Promise<{chip: string, freeHeap: number, uptime: number, firmware: string, connection: string}>}
|
||||
*/
|
||||
export async function getSystemInfo() {
|
||||
const res = await fetch(`${API_BASE}/api/system/info`);
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a reboot command to the ESP32.
|
||||
* @returns {Promise<{message: string}>}
|
||||
*/
|
||||
export async function reboot() {
|
||||
const res = await fetch(`${API_BASE}/api/system/reboot`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (!res.ok) {
|
||||
throw new Error(`HTTP ${res.status}: ${res.statusText}`);
|
||||
}
|
||||
return res.json();
|
||||
}
|
||||
Reference in New Issue
Block a user