24 lines
607 B
Plaintext
24 lines
607 B
Plaintext
// backend/api.js
|
|
import express from 'express';
|
|
import fs from 'fs/promises';
|
|
import path from 'path';
|
|
|
|
const app = express();
|
|
const PORT = 3000;
|
|
const DATA_FILE = path.join(process.cwd(), 'data/metrics.json');
|
|
|
|
app.use(express.static('frontend'));
|
|
app.use(express.json());
|
|
|
|
app.get('/api/metrics', async (_, res) => {
|
|
try {
|
|
const data = await fs.readFile(DATA_FILE, 'utf-8');
|
|
res.json(JSON.parse(data));
|
|
} catch (err) {
|
|
res.status(500).json({ error: 'Failed to read metrics' });
|
|
}
|
|
});
|
|
|
|
app.listen(PORT, () => {
|
|
console.log(`🚀 Dashboard API running on http://localhost:${PORT}`);
|
|
}); |