2.6 KiB
2.6 KiB
Koneksi Frontend ke Backend
Backend Production URL
Backend sudah di-deploy di Railway:
https://backend-sterilisasi.com
Konfigurasi
File yang sudah diupdate:
- ✅
src/config.ts- BACKEND_URL diset ke production - ✅
.env- BACKEND_URL diset ke production
Testing Koneksi
1. Test dari Browser/Postman
# Test root endpoint
curl https://backend-sterilisasi.com/
# Test API endpoint
curl https://backend-sterilisasi.com/sterilisasi/running/last
2. Test dari Aplikasi
-
Rebuild aplikasi React Native:
# Stop Metro bundler (Ctrl+C) # Clear cache npx react-native start --reset-cache # Di terminal lain, run aplikasi npx react-native run-android # atau npx react-native run-ios -
Buka aplikasi dan coba fitur yang menggunakan backend:
- Dashboard → pilih alat → Set parameters → Mulai Proses
- History → lihat riwayat dari database
Switching Environment
Development (Local Backend)
Edit src/config.ts:
export const BACKEND_URL = 'http://10.0.2.2:5000'; // Android Emulator
// atau
export const BACKEND_URL = 'http://192.168.1.155:5000'; // Device fisik
Production (Railway)
Edit src/config.ts:
export const BACKEND_URL = 'https://backend-sterilisasi.com';
PENTING: Setelah mengubah config, restart Metro bundler dengan --reset-cache
Troubleshooting
Error: Network request failed
- Cek koneksi internet - Pastikan device/emulator terkoneksi internet
- Cek URL backend - Pastikan
https://backend-sterilisasi.combisa diakses dari browser - Cek CORS - Backend sudah menggunakan CORS, seharusnya tidak ada masalah
- Clear cache - Restart Metro bundler dengan
--reset-cache
Error: 404 Not Found
- Cek endpoint - Pastikan endpoint yang dipanggil benar
- Cek backend logs - Lihat logs di Railway dashboard
- Test dengan curl - Test endpoint dari terminal/Postman
Data tidak muncul
- Cek database - Pastikan MongoDB Atlas terkoneksi
- Cek MQTT - Pastikan alat bisa kirim data ke MQTT broker
- Cek logs - Lihat logs di Railway untuk error
Monitoring Backend
- Buka Railway dashboard: https://railway.app
- Pilih project
backend-sterilisasi - Tab "Logs" - Lihat real-time logs
- Tab "Metrics" - Lihat usage (CPU, RAM, Network)
- Tab "Deployments" - Lihat history deployment
Update Backend
Jika ada perubahan di backend:
cd Back-end
git add .
git commit -m "Update: deskripsi perubahan"
git push
Railway akan otomatis re-deploy dalam beberapa menit.