5.3 KiB
5.3 KiB
🔍 Check Railway Deployment Status
📊 Latest Commits
- 5c950c1 - Add better error handling and logging ← LATEST
- 794201c - Add missing websocket-stream dependency
- b08ad68 - Fix: Remove digitalRead error and disable MQTT broker
🚀 Deployment Progress
Build Status: ✅ SUCCESS
✓ Dependencies installed
✓ Build completed
✓ Image pushed (275.6 MB)
Container Status: ⏳ STARTING
Tunggu 30-60 detik untuk container start.
🧪 Test Deployment
Wait 1 Minute, Then Test:
# PowerShell
Start-Sleep -Seconds 60
Invoke-WebRequest -Uri "https://web-production-47eb.up.railway.app/" -UseBasicParsing
Expected Response:
{
"status": "OK",
"message": "Pengering Ikan Backend Server",
"version": "1.0.0",
"uptime": 12.34,
"timestamp": "2026-05-28T..."
}
📋 Improvements in Latest Commit
1. Better Database Error Handling
try {
const connected = await db.testConnection();
if (connected) {
await db.initDatabase();
}
} catch (error) {
console.error('❌ Database initialization error:', error.message);
console.warn('⚠️ Continuing without database...');
}
Benefit: Server tetap start meskipun database gagal connect.
2. Express Server Error Handling
const server = app.listen(PORT, '0.0.0.0', () => {
console.log('✅ Server is ready!');
});
server.on('error', (error) => {
console.error('❌ Server error:', error);
process.exit(1);
});
Benefit: Error lebih jelas di logs.
3. Global Error Handlers
process.on('uncaughtException', (error) => {
console.error('❌ Uncaught Exception:', error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('❌ Unhandled Rejection:', reason);
process.exit(1);
});
Benefit: Catch semua error yang tidak ter-handle.
4. Bind to 0.0.0.0
app.listen(PORT, '0.0.0.0', () => {
// Server accessible from outside
});
Benefit: Server bisa diakses dari luar container.
🔍 How to Check Railway Logs
Via Railway Dashboard:
- Go to https://railway.app/
- Login to your account
- Select your project
- Click on your service
- Click "Deployments" tab
- Click latest deployment
- View "Deploy Logs" and "Application Logs"
Look for These Logs:
Success:
🔄 Initializing database connection...
✅ Database connected, initializing tables...
✅ Database tables initialized
✅ Latest data loaded from database
ℹ️ MQTT Broker disabled (use external MQTT broker like HiveMQ)
ℹ️ WebSocket MQTT disabled
🚀 REST API running on port 3000
✅ Server is ready!
Failure:
❌ Database initialization error: ...
❌ Server error: ...
❌ Uncaught Exception: ...
🛠️ If Still Getting 502
Check 1: Railway Service Status
- Go to Railway Dashboard
- Check if service is "Active" (green)
- If "Crashed" (red), view logs for error
Check 2: Environment Variables
Ensure these are set:
MYSQL_URL=mysql://root:...@mysql.railway.internal:3306/railway
NODE_ENV=production
PORT=3000
Check 3: Database Connection
Test database separately:
-- Connect to Railway MySQL via CLI
railway connect mysql
-- Check if database exists
SHOW DATABASES;
-- Check if tables exist
USE railway;
SHOW TABLES;
Check 4: Restart Service
In Railway Dashboard:
- Click service
- Click "Settings"
- Scroll down
- Click "Restart"
📝 Troubleshooting Steps
Step 1: Wait Full 2 Minutes
Railway needs time to:
- Pull new code
- Build image
- Push image
- Start container
- Initialize app
Step 2: Test Health Check
Invoke-WebRequest -Uri "https://web-production-47eb.up.railway.app/" -UseBasicParsing
Step 3: If 502, Check Logs
Look for error messages in Railway logs.
Step 4: Test Database
Invoke-WebRequest -Uri "https://web-production-47eb.up.railway.app/api/database/test" -UseBasicParsing
Step 5: Initialize Tables
Invoke-WebRequest -Uri "https://web-production-47eb.up.railway.app/api/database/init" -Method POST -UseBasicParsing
⏰ Timeline
- 04:40 UTC - Build completed
- 04:40 UTC - Image pushed
- 04:40 UTC - Container starting
- 04:41 UTC - Expected: Container ready
- 04:42 UTC - Test endpoints
Current Time: Check your clock
Wait Until: 04:42 UTC (or 2 minutes from build completion)
🎯 Next Steps
- Wait 2 minutes from build completion
- Test health check endpoint
- If success: Initialize database and test with ESP32
- If 502: Check Railway logs for specific error
- If database error: Check MySQL service status
✅ Success Criteria
- Health check returns 200 OK
- Database test returns success
- Database init creates tables
- Latest data endpoint returns data
- Stats endpoint returns statistics
📞 Support
If still having issues:
- Check
TROUBLESHOOTING_RAILWAY.md - View Railway logs for specific errors
- Test locally:
npm install && npm start - Check Railway status: https://status.railway.app/
Latest Deploy: 5c950c1 - Add better error handling and logging
Status: ⏳ Deploying...
ETA: 2 minutes from build completion
Good luck! 🚀