feat: basic cluster overview
This commit is contained in:
64
index.js
Normal file
64
index.js
Normal file
@@ -0,0 +1,64 @@
|
||||
const express = require('express');
|
||||
const path = require('path');
|
||||
const SporeApiClient = require('./src/client');
|
||||
|
||||
const app = express();
|
||||
const PORT = process.env.PORT || 3001;
|
||||
|
||||
// Initialize the SPORE API client
|
||||
const sporeClient = new SporeApiClient('http://10.0.1.60');
|
||||
|
||||
// Serve static files from public directory
|
||||
app.use(express.static(path.join(__dirname, 'public')));
|
||||
|
||||
// Serve the main HTML page
|
||||
app.get('/', (req, res) => {
|
||||
res.sendFile(path.join(__dirname, 'public', 'index.html'));
|
||||
});
|
||||
|
||||
// API endpoint to get cluster members
|
||||
app.get('/api/cluster/members', async (req, res) => {
|
||||
try {
|
||||
const members = await sporeClient.getClusterStatus();
|
||||
res.json(members);
|
||||
} catch (error) {
|
||||
console.error('Error fetching cluster members:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to fetch cluster members',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// API endpoint to get task status
|
||||
app.get('/api/tasks/status', async (req, res) => {
|
||||
try {
|
||||
const taskStatus = await sporeClient.getTaskStatus();
|
||||
res.json(taskStatus);
|
||||
} catch (error) {
|
||||
console.error('Error fetching task status:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to fetch task status',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// API endpoint to get system status
|
||||
app.get('/api/node/status', async (req, res) => {
|
||||
try {
|
||||
const systemStatus = await sporeClient.getSystemStatus();
|
||||
res.json(systemStatus);
|
||||
} catch (error) {
|
||||
console.error('Error fetching system status:', error);
|
||||
res.status(500).json({
|
||||
error: 'Failed to fetch system status',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Start the server
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on http://localhost:${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user