Files
LuHost/public/js/shared-status.js
Nathan Schneider 3aed09b60f Initial commit: LuHost - Luanti Server Management Web Interface
A modern web interface for Luanti (Minetest) server management with ContentDB integration.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-23 17:32:37 -06:00

39 lines
1.5 KiB
JavaScript

// Shared server status functionality for all pages
async function updateServerStatus(statusElementId) {
try {
const response = await fetch('/api/server/status');
// Check for authentication redirect
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('text/html')) {
console.warn('Authentication required for server status');
// Silently fail for status updates, don't redirect automatically
return;
}
if (!response.ok) {
throw new Error('HTTP error! status: ' + response.status);
}
const status = await response.json();
updateStatusElement(statusElementId, status);
} catch (error) {
console.error('Failed to update server status:', error);
// Show error state
const statusElement = document.getElementById(statusElementId);
if (statusElement) {
statusElement.textContent = 'Error';
statusElement.className = 'status status-stopped';
}
}
}
function updateStatusElement(elementId, status) {
const statusElement = document.getElementById(elementId);
if (statusElement) {
const statusText = status.statusText || (status.isRunning ? 'running' : 'stopped');
statusElement.textContent = statusText.charAt(0).toUpperCase() + statusText.slice(1);
statusElement.className = `status status-${statusText}`;
}
}