feat: implement notification system with polling and event handling; add device ID middleware and cleanup logic

This commit is contained in:
2025-11-13 18:10:50 +01:00
parent 6b5ae7f578
commit a8c7b859a8
19 changed files with 354 additions and 25 deletions
+9
View File
@@ -3,11 +3,14 @@ import cors from 'cors';
import dotenv from 'dotenv';
import { initializeDatabase } from './db';
import { authenticatePassword } from './middleware/auth';
import { deviceIdMiddleware } from './middleware/device';
import listRoutes from './routes/listRoutes';
import fieldRoutes from './routes/fieldRoutes';
import itemRoutes from './routes/itemRoutes';
import syncRoutes from './routes/syncRoutes';
import webRoutes from './routes/webRoutes';
import notificationRoutes from './routes/notificationRoutes';
import { startNotificationCleanup } from './notifications';
dotenv.config();
@@ -25,12 +28,15 @@ app.get('/health', (req, res) => {
// Apply authentication middleware to all API routes
app.use('/api', authenticatePassword);
// Attach device id for downstream routes
app.use('/api', deviceIdMiddleware);
// Routes (protected by auth)
app.use('/api/lists', listRoutes);
app.use('/api/fields', fieldRoutes);
app.use('/api/items', itemRoutes);
app.use('/api', syncRoutes);
app.use('/api', notificationRoutes);
// Web UI (no auth required, must be last to not interfere with API routes)
app.use('/', webRoutes);
@@ -46,6 +52,9 @@ app.use('/', webRoutes);
console.log('- Items');
console.log('- ItemValues');
// Start retention cleanup for notifications
startNotificationCleanup();
// Start HTTP server (WebSocket removed)
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);