Feature: Convert from Node.js/Express to Python/Flask
BREAKING CHANGE: Replaced Node.js backend with Python Flask Reason: npm not available on production server, Python/pip is available. Changes: - Created app.py (Flask) to replace server.js (Node.js) - Created requirements.txt with only 2 dependencies (Flask, mysql-connector-python) - Updated README.md with Flask installation and deployment instructions - Maintained all existing functionality: * Same API endpoints (/api/notifications, /health) * Same database queries (isshopfloor filter, 72-hour window) * Same priority sorting (incidents first) * Serves static files from public/ directory * Same environment variable configuration Dependencies: - Flask==3.0.0 - mysql-connector-python==8.2.0 The public/index.html frontend remains unchanged - only the backend was converted. Tested and verified: - API endpoint returns correct data - Health check responds - Dashboard displays properly - Database connectivity working - PM2 process manager compatible 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
95
README.md
95
README.md
@@ -9,15 +9,18 @@ Real-time display dashboard for showing current and upcoming events on the shopf
|
||||
## Features
|
||||
|
||||
- **Live Data Updates**: Auto-refreshes every 10 seconds via AJAX (no page reload)
|
||||
- **48-Hour Window**: Shows current events and upcoming events within next 48 hours
|
||||
- **72-Hour Window**: Shows current events and upcoming events within next 72 hours
|
||||
- **Shopfloor Filtering**: Only displays notifications marked for shopfloor display
|
||||
- **Type-Based Color Coding**: Visual severity indicators (Red=Incident, Yellow=Change, Green=Awareness)
|
||||
- **Priority Sorting**: Critical incidents always shown first
|
||||
- **Real-Time Clock**: Always-on clock display
|
||||
- **Connection Monitoring**: Visual indicator shows live connection status
|
||||
- **GE Aerospace Branding**: Official colors, fonts, and logo
|
||||
|
||||
## Technology Stack
|
||||
|
||||
- **Backend**: Node.js with Express
|
||||
- **Database**: MySQL 5.6
|
||||
- **Backend**: Python 3 with Flask
|
||||
- **Database**: MySQL 5.6+
|
||||
- **Frontend**: Vanilla JavaScript (no frameworks)
|
||||
- **Styling**: Custom CSS with GE Aerospace brand colors
|
||||
|
||||
@@ -25,7 +28,7 @@ Real-time display dashboard for showing current and upcoming events on the shopf
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Node.js 16+ and npm
|
||||
- Python 3.8+ with pip
|
||||
- MySQL 5.6+ database
|
||||
- Access to ShopDB database
|
||||
|
||||
@@ -33,7 +36,7 @@ Real-time display dashboard for showing current and upcoming events on the shopf
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Set environment variables (optional)
|
||||
export DB_HOST=localhost
|
||||
@@ -44,10 +47,7 @@ export DB_NAME=shopdb
|
||||
export PORT=3001
|
||||
|
||||
# Start the server
|
||||
npm start
|
||||
|
||||
# Or for development with auto-restart
|
||||
npm run dev
|
||||
python3 app.py
|
||||
```
|
||||
|
||||
## Configuration
|
||||
@@ -99,8 +99,8 @@ Returns server status.
|
||||
|
||||
```
|
||||
shopfloor-dashboard/
|
||||
├── server.js # Express server
|
||||
├── package.json # Dependencies
|
||||
├── app.py # Flask application
|
||||
├── requirements.txt # Python dependencies
|
||||
├── public/
|
||||
│ ├── index.html # Dashboard UI
|
||||
│ └── ge-aerospace-logo.svg
|
||||
@@ -110,17 +110,24 @@ shopfloor-dashboard/
|
||||
|
||||
## Database Schema
|
||||
|
||||
Queries the `notifications` table in ShopDB:
|
||||
Queries the `notifications` table in ShopDB with shopfloor filtering:
|
||||
|
||||
```sql
|
||||
SELECT notificationid, notification, starttime, endtime,
|
||||
ticketnumber, link, isactive
|
||||
FROM notifications
|
||||
WHERE isactive = 1
|
||||
AND (conditions for current/upcoming)
|
||||
ORDER BY starttime ASC
|
||||
SELECT n.notificationid, n.notification, n.starttime, n.endtime,
|
||||
n.ticketnumber, n.link, n.isactive, n.isshopfloor,
|
||||
nt.typename, nt.typecolor
|
||||
FROM notifications n
|
||||
LEFT JOIN notificationtypes nt ON n.notificationtypeid = nt.notificationtypeid
|
||||
WHERE n.isactive = 1
|
||||
AND n.isshopfloor = 1
|
||||
AND (conditions for 72-hour window)
|
||||
ORDER BY n.starttime ASC
|
||||
```
|
||||
|
||||
**Key Fields:**
|
||||
- `isshopfloor`: Boolean flag (0/1) - only events with `1` appear on dashboard
|
||||
- `typecolor`: Used for visual severity indicators (danger/warning/success)
|
||||
|
||||
## Design
|
||||
|
||||
### Colors (GE Aerospace Brand)
|
||||
@@ -173,50 +180,72 @@ git push
|
||||
## Development
|
||||
|
||||
```bash
|
||||
# Install dev dependencies
|
||||
npm install
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Run with auto-restart
|
||||
npm run dev
|
||||
# Run the Flask development server
|
||||
python3 app.py
|
||||
|
||||
# The server will restart automatically when you edit files
|
||||
# The built-in Flask server auto-reloads on code changes when debug=True
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
For production deployment:
|
||||
For production deployment (no pip/npm required on production server):
|
||||
|
||||
1. Use a process manager (PM2, systemd)
|
||||
2. Set environment variables
|
||||
3. Configure reverse proxy (nginx/Apache) if needed
|
||||
4. Enable SSL/TLS for secure connections
|
||||
### Option 1: Package with Dependencies (Recommended)
|
||||
|
||||
### Example with PM2:
|
||||
1. Package entire directory including installed Python packages
|
||||
2. Copy to production server
|
||||
3. Run directly with Python 3
|
||||
4. Use a process manager (systemd, supervisor, or PM2)
|
||||
|
||||
### Option 2: Install on Production
|
||||
|
||||
```bash
|
||||
npm install -g pm2
|
||||
pm2 start server.js --name shopfloor-dashboard
|
||||
# Install dependencies on production
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Run with production WSGI server (recommended)
|
||||
pip install gunicorn
|
||||
gunicorn -w 4 -b 0.0.0.0:3001 app:app
|
||||
|
||||
# Or use PM2 with Python
|
||||
pm2 start app.py --name shopfloor-dashboard --interpreter python3
|
||||
pm2 save
|
||||
pm2 startup
|
||||
```
|
||||
|
||||
**Note**: Flask's built-in server (`python3 app.py`) works for production if using a process manager, but gunicorn is recommended for higher traffic.
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
**Port already in use:**
|
||||
```bash
|
||||
# Use a different port
|
||||
PORT=3001 npm start
|
||||
PORT=3001 python3 app.py
|
||||
```
|
||||
|
||||
**Can't connect to database:**
|
||||
- Verify MySQL is running
|
||||
- Check credentials in environment variables
|
||||
- Check credentials in environment variables or app.py
|
||||
- Ensure database exists and user has permissions
|
||||
- Verify `mysql-connector-python` is installed
|
||||
|
||||
**Dashboard not updating:**
|
||||
- Check browser console for errors
|
||||
- Verify `/api/notifications` endpoint returns data
|
||||
- Check network connectivity
|
||||
- Ensure Flask server is running
|
||||
|
||||
**Python module errors:**
|
||||
```bash
|
||||
# Reinstall dependencies
|
||||
pip install -r requirements.txt
|
||||
|
||||
# Or install individually
|
||||
pip install Flask mysql-connector-python
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
|
||||
Reference in New Issue
Block a user