8.8 KiB
Church SongLyric - Multi-Device Sync Setup Guide
Backend Server Setup
1. Install Dependencies
cd "E:\Documents\Website Projects\Church_SongLyric\backend"
npm install
2. Start the Backend Server
Development (auto-restart on changes):
npm run dev
Production:
npm start
The server will start on http://localhost:5000 by default.
Frontend Configuration
Option 1: Use Settings UI (Recommended)
- Open the app in your browser
- Navigate to Settings page
- Configure Online/DNS Settings:
- Protocol:
httporhttps - Hostname:
localhost(local) or your No-IP hostname (remote) - Port:
5000 - Access Mode: Toggle between Local Storage (offline) and Online (synced)
- Protocol:
- Click Save Settings
- Refresh the page to connect
Option 2: Manual Configuration
Edit frontend/src/api.js and modify:
useLocalStorage: false // Enable backend sync
hostname: "localhost" // Or your No-IP hostname
Local Network Access (Multiple Devices on Same Wi-Fi)
1. Find Your Computer's Local IP
ipconfig
Look for IPv4 Address under your active network adapter (e.g., 192.168.1.50)
2. Configure Frontend Settings
- Hostname: Use your local IP (e.g.,
192.168.1.50) - Port:
5000 - Access Mode: Online
3. Access from Other Devices
Open browser on tablet/phone/laptop and navigate to:
http://192.168.1.50:3000
All devices will now share the same database via the backend server.
External Access Setup (No-IP Dynamic DNS)
Step 1: Create No-IP Account
- Go to https://www.noip.com/
- Sign up for free account (supports 3 hostnames)
- Verify email
Step 2: Create Hostname
- Login to No-IP dashboard
- Navigate to Dynamic DNS → No-IP Hostnames
- Click Create Hostname
- Choose a hostname:
churchlyrics.ddns.net(or your preference) - Set Record Type: A (IPv4 Address)
- Leave IP auto-detected (your current public IP)
- Click Create Hostname
Step 3: Assign Static Local IP (Windows)
- Open Settings → Network & Internet → Ethernet (or Wi-Fi)
- Click Properties
- Click Edit under IP assignment
- Select Manual
- Enable IPv4
- Set:
- IP Address:
192.168.1.50(adjust to your subnet) - Subnet Mask:
255.255.255.0 - Gateway: Your router IP (usually
192.168.1.1) - DNS:
8.8.8.8(Google DNS)
- IP Address:
- Save
Step 4: Configure Router Port Forwarding
- Login to router admin panel (usually
http://192.168.1.1) - Navigate to Port Forwarding or Virtual Server
- Add new rule:
- Service Name: ChurchSongLyric API
- External Port:
5000 - Internal IP:
192.168.1.50(your static IP) - Internal Port:
5000 - Protocol: TCP
- Add another rule for frontend (if exposing React dev server):
- External Port:
3000 - Internal IP:
192.168.1.50 - Internal Port:
3000 - Protocol: TCP
- External Port:
- Save and reboot router if required
Step 5: Install No-IP Dynamic Update Client (DUC)
- Download from https://www.noip.com/download
- Install and login with your No-IP credentials
- Select the hostname you created
- Click Save
- Enable Start on Windows Startup in settings
- The client will auto-update your public IP when it changes
Step 6: Configure Windows Firewall
Allow Backend Port:
New-NetFirewallRule -DisplayName "ChurchSongLyric API" -Direction Inbound -Protocol TCP -LocalPort 5000 -Action Allow
Allow Frontend Port (if needed):
New-NetFirewallRule -DisplayName "ChurchSongLyric Frontend" -Direction Inbound -Protocol TCP -LocalPort 3000 -Action Allow
Or manually:
- Open Windows Security → Firewall & Network Protection
- Click Advanced Settings
- Select Inbound Rules → New Rule
- Choose Port → TCP → Enter
5000 - Select Allow the connection
- Name it:
ChurchSongLyric API - Repeat for port
3000if needed
Step 7: Test External Access
From a mobile device on cellular (not Wi-Fi):
http://churchlyrics.ddns.net:5000/api/songs
Should return JSON (empty array initially).
Step 8: Update Frontend Settings
In Settings UI:
- Protocol:
http - Hostname:
churchlyrics.ddns.net - Port:
5000 - Access Mode: Online
Save and refresh.
Security Hardening (Recommended)
1. Add API Key Authentication
Edit backend/server.js and add middleware:
const API_KEY = process.env.API_KEY || 'your-secret-key-here';
app.use('/api', (req, res, next) => {
const key = req.headers['x-api-key'];
if (key !== API_KEY) {
return res.status(401).json({ error: 'Unauthorized' });
}
next();
});
Update frontend requests to include header:
headers: {
"Content-Type": "application/json",
"X-API-Key": "your-secret-key-here"
}
2. Enable HTTPS (Production)
Install Caddy (reverse proxy with auto HTTPS):
choco install caddy
Create Caddyfile:
churchlyrics.ddns.net {
reverse_proxy localhost:5000
}
Update port forwarding to 443 (HTTPS) instead of 5000.
3. Regular Backups
Schedule automatic backups of backend/data.json:
# Add to Task Scheduler
Copy-Item "E:\Documents\Website Projects\Church_SongLyric\backend\data.json" `
-Destination "E:\Backups\church_data_$(Get-Date -Format yyyyMMdd_HHmmss).json"
4. Restrict WebSocket Origins
In server.js:
wss.on('connection', (ws, req) => {
const origin = req.headers.origin;
const allowed = ['http://localhost:3000', 'http://churchlyrics.ddns.net:3000'];
if (!allowed.includes(origin)) {
ws.close();
return;
}
// ... rest of connection logic
});
Real-Time Sync Features
How It Works
- Backend broadcasts changes via WebSocket when any device creates/updates/deletes data
- All connected clients receive notifications and automatically refresh their UI
- No manual page reload needed
Supported Events
songsChanged: When songs are added/edited/deletedplansChanged: When worship plans are modifiedprofilesChanged: When profiles are updatedprofileSongsChanged: When profile song associations change
Testing Sync
- Open app on two devices (or two browser tabs)
- Create a new song on Device A
- Device B will automatically show the new song without refresh
Troubleshooting
Backend won't start
# Check if port is already in use
Get-NetTCPConnection -LocalPort 5000
# Kill the process if needed
Stop-Process -Id <PID>
Can't connect from other devices
- Verify firewall rules are active
- Check router port forwarding is saved
- Ensure static IP is configured correctly
- Test local connection first (
http://localhost:5000/api/songs)
WebSocket disconnects frequently
- Check network stability
- Ensure No-IP DUC is running and updating
- Verify router isn't closing idle connections (adjust timeout settings)
Data not syncing
- Open browser console (F12)
- Check for WebSocket connection logs:
✅ WebSocket connected= working❌ WebSocket error= connection failed
- Verify
useLocalStorageis set tofalsein Settings - Test API directly:
http://your-host:5000/api/songs
Performance Optimization
Enable Compression
Add to server.js:
import compression from 'compression';
app.use(compression());
Database Migration (Future)
For larger deployments, consider migrating from file-based storage to:
- SQLite: Lightweight, file-based SQL database
- MongoDB: NoSQL document store
- PostgreSQL: Full-featured relational database
Additional Resources
- No-IP Documentation: https://www.noip.com/support
- Express.js Guide: https://expressjs.com/
- WebSocket API: https://developer.mozilla.org/en-US/docs/Web/API/WebSocket
Support
For issues or questions:
- Check backend console for error logs
- Check browser console (F12) for frontend errors
- Verify all ports are open and forwarded correctly
- Test each layer: localhost → LAN → external
Quick Test Commands:
# Test local backend
curl http://localhost:5000/api/songs
# Test from LAN
curl http://192.168.1.50:5000/api/songs
# Test external (from mobile cellular)
curl http://churchlyrics.ddns.net:5000/api/songs