Overview
Browser mode transforms MQTT Explorer from an Electron desktop app into a web application:- Server: Node.js Express server with Socket.io for WebSocket communication
- Frontend: React application bundled with webpack
- Transport: WebSocket RPC replaces Electron IPC
- Authentication: Built-in user authentication with bcrypt password hashing
Docker Deployment
Deploy browser mode with Docker containers (recommended)
Manual Setup
Run directly with Node.js for development or custom deployments
Quick Start
- Production
- Development
Production Deployment
Build Application
- Compiles TypeScript backend (
npx tsc) - Bundles frontend with webpack (
webpack --mode production) - Creates optimized production build in
dist/andapp/build/
Architecture
Client-Server Communication
Browser mode uses Socket.io WebSockets for real-time bidirectional communication:EventBusInterface, allowing application code to work seamlessly in both environments without modification.
Event Bus Abstraction
The event bus provides a unified API:- subscribe(event, handler) - Listen for events from server
- send(event, data) - Send request to server
- request(event, data) - Send request and wait for response
- on(event, handler) - Register event handler on server
WebSocket RPC Protocol
Communication uses a request-response pattern:Authentication
Authentication Modes
- Standard Authentication
- Skip Authentication
Security Features
Browser mode implements multiple layers of authentication security:- Password Hashing: bcrypt with 10 rounds
- Timing Attack Protection: Constant-time string comparison for usernames
- Rate Limiting: Maximum 5 failed attempts per IP per 15 minutes
- Session Tracking: Failed attempts tracked per client IP
- No Credential Logging: In production mode, credentials are not logged
Configuration
Server Configuration
| Environment Variable | Default | Description |
|---|---|---|
PORT | 3000 | Port the server listens on |
NODE_ENV | - | Set to production for production deployments |
ALLOWED_ORIGINS | * | Comma-separated list of allowed CORS origins |
UPGRADE_INSECURE_REQUESTS | false | Enable CSP upgrade-insecure-requests (HTTPS only) |
X_FRAME_OPTIONS | false | Enable X-Frame-Options: SAMEORIGIN header |
Port Configuration
CORS Configuration
In production, configure specific allowed origins:In production with
NODE_ENV=production, wildcard CORS is automatically disabled for security.AI Assistant Configuration
Enable AI-powered MQTT topic analysis:| Environment Variable | Default | Description |
|---|---|---|
LLM_PROVIDER | openai | AI provider: openai or gemini |
OPENAI_API_KEY | - | OpenAI API key (provider-specific) |
GEMINI_API_KEY | - | Google Gemini API key (provider-specific) |
LLM_API_KEY | - | Generic API key (works with either provider) |
LLM_NEIGHBORING_TOPICS_TOKEN_LIMIT | 500 | Token limit for context in AI queries |
Example with OpenAI
Security Architecture
The backend proxies all LLM API requests:- ✅ API keys remain server-side only
- ✅ Keys never embedded in client bundles
- ✅ Keys never transmitted to frontend
- ✅ Backend controls all LLM access
- ✅ Communication via secure WebSocket RPC
If no LLM environment variables are set, the AI Assistant feature is completely hidden from users.
Data Storage
In browser mode, all data is stored server-side:| Path | Content |
|---|---|
data/credentials.json | User authentication credentials |
data/settings.json | Application settings and preferences |
data/certificates/ | Uploaded SSL/TLS certificates |
data/uploads/ | File uploads |
Certificate Upload
Certificates are uploaded through the browser using HTML5 File API:- User selects certificate files via file input
- Files are read client-side as base64
- Base64 data is stored in connection configuration
- Certificates are used when establishing MQTT connections
Maximum certificate file size is 16KB. Larger files will be rejected.
Features & Limitations
Browser Mode Advantages
No Installation
Access from any browser without installing software
Cross-Platform
Works on any device with a modern browser
Remote Access
Deploy on a server for remote team access
Multi-User
Support authentication for multiple users (future)
Browser Mode Limitations
Some desktop features are not available in browser mode:| Feature | Desktop | Browser | Notes |
|---|---|---|---|
| File System Access | ✅ Direct | ❌ Limited | Server-side only |
| Native Dialogs | ✅ Yes | ❌ No | Uses HTML file input |
| Auto-Updates | ✅ Yes | ❌ No | Manual server updates |
| System Tray | ✅ Yes | ❌ No | Desktop-only feature |
| Multiple Windows | ✅ Yes | ✅ Yes | Use browser tabs |
Production Deployment
Security Requirements
HTTPS/TLS Encryption
Always use HTTPS in production to protect credentials and MQTT data in transit.Deploy behind a reverse proxy like nginx or Apache:
HTTP Security Headers
The server uses helmet.js to set security headers:- Content Security Policy (CSP) - Prevents XSS attacks
- HTTP Strict Transport Security (HSTS) - Forces HTTPS (production only)
- X-Content-Type-Options - Prevents MIME sniffing
- X-Frame-Options - Prevents clickjacking (when enabled)
- X-XSS-Protection - Legacy XSS protection
File Upload Security
The server implements protections against malicious uploads:- Maximum file size: 16MB (configurable)
- Path traversal protection: Filename sanitization
- Isolated directories: Files stored in isolated paths
- Real path validation: Prevents directory escapes
Debugging
Enable Debug Logging
Enable detailed Socket.IO connection and lifecycle debugging:Debug Namespaces
mqtt-explorer:socketio- General Socket.IO events and metricsmqtt-explorer:socketio:connect- Client connection eventsmqtt-explorer:socketio:disconnect- Client disconnection and cleanupmqtt-explorer:socketio:subscriptions- Subscription lifecycle trackingmqtt-explorer:socketio:connections- MQTT connection ownership
Example Output
Troubleshooting
Authentication fails
Authentication fails
-
Check the console output for generated credentials:
-
Clear browser session storage:
-
Restart server to regenerate credentials:
WebSocket connection fails
WebSocket connection fails
-
Check server is running:
-
Check browser console for Socket.io errors:
- Open DevTools (F12)
- Look for WebSocket connection errors
- Check Network tab for failed requests
-
Verify firewall rules allow port 3000:
-
Test WebSocket connection:
Certificate upload fails
Certificate upload fails
- Verify certificate file is under 16KB
- Ensure certificate is in PEM format
- Check browser console for JavaScript errors
- Verify sufficient disk space in
data/certificates/
High memory usage
High memory usage
Memory usage scales with:
- Number of connected clients
- Number of active MQTT connections
- Volume of MQTT messages
Build Scripts Reference
Frompackage.json:
Next Steps
Docker Deployment
Deploy browser mode with Docker for easier management
Security Guide
Learn about security best practices and hardening