Stream CrossPointWebServer data over JSON APIs (#97)
## Summary * HTML files are now static, streamed directly to the client without modification * For any dynamic values, load via JSON APIs * For files page, we stream the JSON content as we scan the directory to avoid holding onto too much data ## Additional details * We were previously building up a very large string all generated on the X4 directly, we should be leveraging the browser * Fixes https://github.com/daveallie/crosspoint-reader/issues/94
This commit is contained in:
@@ -83,7 +83,7 @@
|
||||
<h2>Device Status</h2>
|
||||
<div class="info-row">
|
||||
<span class="label">Version</span>
|
||||
<span class="value">%VERSION%</span>
|
||||
<span class="value" id="version"></span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">WiFi Status</span>
|
||||
@@ -91,11 +91,11 @@
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">IP Address</span>
|
||||
<span class="value">%IP_ADDRESS%</span>
|
||||
<span class="value" id="ip-address"></span>
|
||||
</div>
|
||||
<div class="info-row">
|
||||
<span class="label">Free Memory</span>
|
||||
<span class="value">%FREE_HEAP% bytes</span>
|
||||
<span class="value" id="free-heap"></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -104,5 +104,26 @@
|
||||
CrossPoint E-Reader • Open Source
|
||||
</p>
|
||||
</div>
|
||||
<script>
|
||||
async function fetchStatus() {
|
||||
try {
|
||||
const response = await fetch('/api/status');
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch status: ' + response.status + ' ' + response.statusText);
|
||||
}
|
||||
const data = await response.json();
|
||||
document.getElementById('version').textContent = data.version || 'N/A';
|
||||
document.getElementById('ip-address').textContent = data.ip || 'N/A';
|
||||
document.getElementById('free-heap').textContent = data.freeHeap
|
||||
? data.freeHeap.toLocaleString() + ' bytes'
|
||||
: 'N/A';
|
||||
} catch (error) {
|
||||
console.error('Error fetching status:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Fetch status on page load
|
||||
window.onload = fetchStatus;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user