- Node.js Express server with MySQL integration - Real-time event dashboard with live updates - GE Aerospace branding and design - Auto-refresh every 10 seconds (AJAX) - Shows current and upcoming events (48 hour window) - Connection status monitoring - Optimized for TV display 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
const express = require('express');
|
|
const mysql = require('mysql2');
|
|
const path = require('path');
|
|
|
|
const app = express();
|
|
const PORT = process.env.PORT || 3000;
|
|
|
|
// Database connection pool
|
|
const pool = mysql.createPool({
|
|
host: process.env.DB_HOST || 'localhost',
|
|
port: process.env.DB_PORT || 3306,
|
|
user: process.env.DB_USER || '570005354',
|
|
password: process.env.DB_PASS || '570005354',
|
|
database: process.env.DB_NAME || 'shopdb',
|
|
waitForConnections: true,
|
|
connectionLimit: 10,
|
|
queueLimit: 0
|
|
});
|
|
|
|
// Promisify for async/await
|
|
const promisePool = pool.promise();
|
|
|
|
// Serve static files
|
|
app.use(express.static('public'));
|
|
|
|
// API endpoint to get notifications
|
|
app.get('/api/notifications', async (req, res) => {
|
|
try {
|
|
const now = new Date();
|
|
const future = new Date(now.getTime() + (48 * 60 * 60 * 1000)); // 48 hours from now
|
|
|
|
const [rows] = await promisePool.query(
|
|
`SELECT notificationid, notification, starttime, endtime, ticketnumber, link, isactive
|
|
FROM notifications
|
|
WHERE isactive = 1
|
|
AND (
|
|
(starttime <= ? AND (endtime IS NULL OR endtime >= ?))
|
|
OR (starttime BETWEEN ? AND ?)
|
|
)
|
|
ORDER BY starttime ASC`,
|
|
[future, now, now, future]
|
|
);
|
|
|
|
// Categorize notifications
|
|
const currentEvents = [];
|
|
const upcomingEvents = [];
|
|
|
|
rows.forEach(notification => {
|
|
const start = new Date(notification.starttime);
|
|
const end = notification.endtime ? new Date(notification.endtime) : null;
|
|
|
|
if (start <= now && (end === null || end >= now)) {
|
|
currentEvents.push(notification);
|
|
} else {
|
|
upcomingEvents.push(notification);
|
|
}
|
|
});
|
|
|
|
res.json({
|
|
success: true,
|
|
timestamp: new Date().toISOString(),
|
|
current: currentEvents,
|
|
upcoming: upcomingEvents
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('Database error:', error);
|
|
res.status(500).json({
|
|
success: false,
|
|
error: 'Database error: ' + error.message
|
|
});
|
|
}
|
|
});
|
|
|
|
// Health check endpoint
|
|
app.get('/health', (req, res) => {
|
|
res.json({ status: 'ok', timestamp: new Date().toISOString() });
|
|
});
|
|
|
|
// Start server
|
|
app.listen(PORT, () => {
|
|
console.log(`Shopfloor Dashboard running on port ${PORT}`);
|
|
console.log(`Access at: http://localhost:${PORT}`);
|
|
});
|
|
|
|
// Graceful shutdown
|
|
process.on('SIGTERM', () => {
|
|
console.log('SIGTERM signal received: closing HTTP server');
|
|
pool.end(() => {
|
|
console.log('Database pool closed');
|
|
process.exit(0);
|
|
});
|
|
});
|