feat: serve static files, relay example
This commit is contained in:
165
examples/base/data/public/index.html
Normal file
165
examples/base/data/public/index.html
Normal file
@@ -0,0 +1,165 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Spore</title>
|
||||
<style>
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
margin: 0;
|
||||
padding: 20px;
|
||||
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
||||
color: white;
|
||||
min-height: 100vh;
|
||||
}
|
||||
.container {
|
||||
max-width: 800px;
|
||||
margin: 0 auto;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
backdrop-filter: blur(10px);
|
||||
border-radius: 20px;
|
||||
padding: 30px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
h1 {
|
||||
text-align: center;
|
||||
margin-bottom: 30px;
|
||||
font-size: 2.5em;
|
||||
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
.status-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||
gap: 20px;
|
||||
margin-bottom: 30px;
|
||||
}
|
||||
.status-card {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
border-radius: 15px;
|
||||
padding: 20px;
|
||||
text-align: center;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
.status-card:hover {
|
||||
transform: translateY(-5px);
|
||||
}
|
||||
.status-value {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
margin: 10px 0;
|
||||
}
|
||||
.api-section {
|
||||
margin-top: 30px;
|
||||
}
|
||||
.api-links {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
justify-content: center;
|
||||
}
|
||||
.api-link {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
color: white;
|
||||
text-decoration: none;
|
||||
padding: 10px 20px;
|
||||
border-radius: 25px;
|
||||
transition: all 0.3s ease;
|
||||
border: 2px solid transparent;
|
||||
}
|
||||
.api-link:hover {
|
||||
background: rgba(255, 255, 255, 0.3);
|
||||
border-color: rgba(255, 255, 255, 0.5);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
.loading {
|
||||
text-align: center;
|
||||
font-style: italic;
|
||||
opacity: 0.7;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>🍄 Spore Node</h1>
|
||||
|
||||
<div class="status-grid">
|
||||
<div class="status-card">
|
||||
<h3>Node Status</h3>
|
||||
<div class="status-value" id="nodeStatus">Loading...</div>
|
||||
</div>
|
||||
<div class="status-card">
|
||||
<h3>Network</h3>
|
||||
<div class="status-value" id="networkStatus">Loading...</div>
|
||||
</div>
|
||||
<div class="status-card">
|
||||
<h3>Tasks</h3>
|
||||
<div class="status-value" id="taskStatus">Loading...</div>
|
||||
</div>
|
||||
<div class="status-card">
|
||||
<h3>Cluster</h3>
|
||||
<div class="status-value" id="clusterStatus">Loading...</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="api-section">
|
||||
<h2>API Endpoints</h2>
|
||||
<div class="api-links">
|
||||
<a href="/api/node/status" class="api-link">Node Status</a>
|
||||
<a href="/api/network/status" class="api-link">Network Status</a>
|
||||
<a href="/api/tasks/status" class="api-link">Tasks Status</a>
|
||||
<a href="/api/cluster/members" class="api-link">Cluster Members</a>
|
||||
<a href="/api/node/endpoints" class="api-link">All Endpoints</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Load initial data
|
||||
async function loadStatus() {
|
||||
try {
|
||||
const [nodeResponse, networkResponse, taskResponse, clusterResponse] = await Promise.all([
|
||||
fetch('/api/node/status').then(r => r.json()).catch(() => null),
|
||||
fetch('/api/network/status').then(r => r.json()).catch(() => null),
|
||||
fetch('/api/tasks/status').then(r => r.json()).catch(() => null),
|
||||
fetch('/api/cluster/members').then(r => r.json()).catch(() => null)
|
||||
]);
|
||||
|
||||
// Update node status
|
||||
if (nodeResponse) {
|
||||
document.getElementById('nodeStatus').textContent =
|
||||
nodeResponse.uptime ? `${Math.floor(nodeResponse.uptime / 1000)}s` : 'Online';
|
||||
}
|
||||
|
||||
// Update network status
|
||||
if (networkResponse) {
|
||||
document.getElementById('networkStatus').textContent =
|
||||
networkResponse.connected ? 'Connected' : 'Disconnected';
|
||||
}
|
||||
|
||||
// Update task status
|
||||
if (taskResponse) {
|
||||
const activeTasks = taskResponse.tasks ?
|
||||
taskResponse.tasks.filter(t => t.status === 'running').length : 0;
|
||||
document.getElementById('taskStatus').textContent = `${activeTasks} active`;
|
||||
}
|
||||
|
||||
// Update cluster status
|
||||
if (clusterResponse) {
|
||||
const memberCount = clusterResponse.members ?
|
||||
Object.keys(clusterResponse.members).length : 0;
|
||||
document.getElementById('clusterStatus').textContent = `${memberCount} nodes`;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading status:', error);
|
||||
}
|
||||
}
|
||||
|
||||
// Load status on page load
|
||||
loadStatus();
|
||||
|
||||
// Refresh status every 5 seconds
|
||||
setInterval(loadStatus, 5000);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user