# Hoppscotch Fix - Step-by-Step Guide
## π **Step-by-Step Fix Hoppscotch (Dari Error 502 β Sukses)**
Berikut rangkuman lengkap langkah-langkah yang kita lakukan untuk memperbaiki Hoppscotch.
---
### π **STEP 1: Identifikasi Masalah Awal**
**Gejala:**
- Co-worker tidak bisa load workspace list di Hoppscotch (loading terus)
- Error di log: `502 Bad Gateway`
**Diagnosa:**
```bash
# Cek log container hoppscotch
docker logs --tail=100 48fc01c8f9a2 2>&1 | grep -i error
Hasil:
dial tcp [::1]:8080: connect: connection refused
β Caddy (reverse proxy) tidak bisa konek ke backend service.
π STEP 2: Cek Status Container & Port
# Cek container yang running
docker ps --filter "publish=8080"
docker ps -a | grep hoppscotch
Hasil: Container hoppscotch sudah running tapi backend-nya mati.
Cek apakah ada yang listen di port 9502:
sudo netstat -tulpn | grep 9502
Hasil: 0.0.0.0:9502 β ada port mapping, tapi service di dalamnya mati.
π STEP 3: Cek Log Lengkap Container
docker logs -f af2efe1a9953
Dari log terlihat:
- β
Backend server mulai jalan:
Backend Server | Port: 8080 - β
Semua route terdaftar:
/graphql,/ping,/auth, dll. - β
Ada request sukses:
POST /graphql 200 - β Tapi Caddy masih error:
dial tcp [::1]:8080: connection refused
Kesimpulan: Backend jalan di 127.0.0.1:8080, tapi Caddy coba pake localhost:8080 (IPv6 ::1).
π STEP 4: Cek Konfigurasi Caddy
# Masuk ke container
docker exec -it af2efe1a9953 sh
# Lihat konfigurasi Caddy
cat /etc/caddy/aio-subpath-access.Caddyfile
Isi Caddyfile:
handle_path /backend* {
reverse_proxy localhost:8080 # <-- MASALAH: pake localhost (IPv6)
}
π§ STEP 5: Perbaiki Konfigurasi Caddy
Ganti localhost menjadi 127.0.0.1 (IPv4):
docker exec af2efe1a9953 sed -i 's/localhost:8080/127.0.0.1:8080/g' /etc/caddy/aio-subpath-access.Caddyfile
Verifikasi:
docker exec af2efe1a9953 cat /etc/caddy/aio-subpath-access.Caddyfile | grep reverse_proxy
Hasil:
reverse_proxy 127.0.0.1:8080
π§ STEP 6: Restart Container
docker restart af2efe1a9953
# Tunggu beberapa detik
sleep 10
π§ STEP 7: Update Konfigurasi Nginx Host
Edit Nginx:
sudo nano /etc/nginx/sites-available/hoppscotch
Tambahkan location /backend/:
location /backend/ {
proxy_pass http://127.0.0.1:9500/backend/; # Lewat Caddy di container
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# WebSocket support (penting untuk Hoppscotch)
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
Test & Reload:
sudo nginx -t
sudo systemctl reload nginx
β STEP 8: Test Endpoint
Test dari host (seharusnya 400 - CSRF error, bukan 502):
curl -v https://hoppscotch.konstruksi.ai/backend/graphql
Hasil:
< HTTP/2 400
< content-type: application/json
{"errors":[{"message":"This operation has been blocked as a potential Cross-Site Request Forgery (CSRF)..."}]}
β SUKSES! Response 400 = backend sudah jalan.
β STEP 9: Test dengan Request Valid
curl -X POST https://hoppscotch.konstruksi.ai/backend/graphql \
-H "Content-Type: application/json" \
-d '{"query":"{ __typename }"}'
Hasil:
{"data":{"__typename":"Query"}}
β Backend benar-benar berfungsi!
π― STEP 10: Verifikasi Hoppscotch di Browser
- Buka
https://hoppscotch.konstruksi.ai - Login dengan GitHub
- Cek workspace list β sudah bisa load!
π Ringkasan Root Cause & Fix
| Masalah | Penyebab | Solusi |
|---|---|---|
| 502 Bad Gateway | Caddy pake IPv6 ([::1]:8080), backend listen di IPv4 (127.0.0.1:8080) |
Ubah Caddyfile: localhost:8080 β 127.0.0.1:8080 |
| Nginx 502 | Nginx gak ada konfigurasi /backend/* |
Tambahkan location /backend/ di Nginx |
| Port mapping | Backend listen di 8080, bukan 3170 | Biarkan mapping 9502:3170 (tidak dipakai) |
π Command Penting yang Digunakan
# Lihat log error
docker logs --tail=100 <container> 2>&1 | grep -i error
# Follow log live
docker logs -f <container>
# Masuk ke container
docker exec -it <container> sh
# Edit file di container
docker exec <container> sed -i 's/old/new/g' /path/to/file
# Restart container
docker restart <container>
# Edit Nginx
sudo nano /etc/nginx/sites-available/hoppscotch
# Reload Nginx
sudo nginx -t && sudo systemctl reload nginx
π Tips Debugging Kedepan
- Cek log dulu:
docker logs --tail=50 <container> - Cek dari dalam container:
docker exec <container> curl http://127.0.0.1:8080/graphql - Cek Nginx:
sudo nginx -t - Test endpoint langsung:
curl -v https://domain.com/path
π Arsitektur Akhir
Browser
β
https://hoppscotch.konstruksi.ai
β
Nginx (Host)
βββ / β http://127.0.0.1:9500 (Caddy β Frontend)
βββ /backend/* β http://127.0.0.1:9500/backend/* (Caddy β Backend)
β
Container: hoppscotch (af2efe1a9953)
βββ Caddy (port 9500)
β βββ /backend/* β reverse_proxy 127.0.0.1:8080
βββ Backend Server (port 8080)
βββ /graphql, /ping, /auth, dll.
β Status Akhir
- β
Frontend Hoppscotch jalan di
https://hoppscotch.konstruksi.ai - β
Backend GraphQL jalan di
https://hoppscotch.konstruksi.ai/backend/graphql - β WebSocket support untuk realtime
- β Co-worker bisa login dan load workspace list