feat: replace SSE with Grafana-style client polling and rich date presets
This commit is contained in:
@@ -61,32 +61,6 @@ const verifyToken = (req, res, next) => {
|
||||
});
|
||||
};
|
||||
|
||||
const sseClients = new Set();
|
||||
|
||||
// SSE Endpoint for real-time updates
|
||||
app.get('/api/stream', (req, res) => {
|
||||
res.setHeader('Content-Type', 'text/event-stream');
|
||||
res.setHeader('Cache-Control', 'no-cache');
|
||||
res.setHeader('Connection', 'keep-alive');
|
||||
res.setHeader('X-Accel-Buffering', 'no'); // Bypass Nginx Proxy Manager buffering
|
||||
res.flushHeaders();
|
||||
|
||||
// Send initial connection event
|
||||
res.write('data: {"connected": true}\n\n');
|
||||
|
||||
// Keep connection alive through Nginx/Cloudflare
|
||||
const keepAlive = setInterval(() => {
|
||||
res.write(':\n\n'); // SSE comment to prevent idle timeout
|
||||
}, 15000);
|
||||
|
||||
sseClients.add(res);
|
||||
|
||||
req.on('close', () => {
|
||||
clearInterval(keepAlive);
|
||||
sseClients.delete(res);
|
||||
});
|
||||
});
|
||||
|
||||
// Login Endpoint
|
||||
app.post('/api/login', (req, res) => {
|
||||
const { email, password } = req.body;
|
||||
@@ -169,12 +143,6 @@ app.post('/api/data', authenticateAPIKey, async (req, res) => {
|
||||
}
|
||||
|
||||
await client.query('COMMIT');
|
||||
|
||||
// Broadcast update to all connected SSE clients
|
||||
const broadcastMessage = `data: {"type": "update"}\n\n`;
|
||||
for (const clientRes of sseClients) {
|
||||
clientRes.write(broadcastMessage);
|
||||
}
|
||||
} catch (error) {
|
||||
await client.query('ROLLBACK');
|
||||
console.error("Database insert error:", error);
|
||||
|
||||
Reference in New Issue
Block a user