254 lines
5.3 KiB
Markdown
254 lines
5.3 KiB
Markdown
# 🔍 Check Railway Deployment Status
|
||
|
||
## 📊 Latest Commits
|
||
|
||
1. **5c950c1** - Add better error handling and logging ← **LATEST**
|
||
2. **794201c** - Add missing websocket-stream dependency
|
||
3. **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
|
||
# PowerShell
|
||
Start-Sleep -Seconds 60
|
||
Invoke-WebRequest -Uri "https://web-production-47eb.up.railway.app/" -UseBasicParsing
|
||
```
|
||
|
||
### Expected Response:
|
||
```json
|
||
{
|
||
"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
|
||
```javascript
|
||
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
|
||
```javascript
|
||
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
|
||
```javascript
|
||
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
|
||
```javascript
|
||
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:
|
||
|
||
1. Go to https://railway.app/
|
||
2. Login to your account
|
||
3. Select your project
|
||
4. Click on your service
|
||
5. Click "Deployments" tab
|
||
6. Click latest deployment
|
||
7. 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:
|
||
```sql
|
||
-- 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:
|
||
1. Pull new code
|
||
2. Build image
|
||
3. Push image
|
||
4. Start container
|
||
5. Initialize app
|
||
|
||
### Step 2: Test Health Check
|
||
```powershell
|
||
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
|
||
```powershell
|
||
Invoke-WebRequest -Uri "https://web-production-47eb.up.railway.app/api/database/test" -UseBasicParsing
|
||
```
|
||
|
||
### Step 5: Initialize Tables
|
||
```powershell
|
||
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
|
||
|
||
1. **Wait 2 minutes** from build completion
|
||
2. **Test health check** endpoint
|
||
3. **If success:** Initialize database and test with ESP32
|
||
4. **If 502:** Check Railway logs for specific error
|
||
5. **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:
|
||
1. Check `TROUBLESHOOTING_RAILWAY.md`
|
||
2. View Railway logs for specific errors
|
||
3. Test locally: `npm install && npm start`
|
||
4. 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! 🚀
|