135dika revised this gist 1 month ago. Go to revision
1 file changed, 258 insertions
fix_hoppscotch.md(file created)
| @@ -0,0 +1,258 @@ | |||
| 1 | + | ``` | |
| 2 | + | # Hoppscotch Fix - Step-by-Step Guide | |
| 3 | + | ||
| 4 | + | ## 📋 **Step-by-Step Fix Hoppscotch (Dari Error 502 → Sukses)** | |
| 5 | + | ||
| 6 | + | Berikut rangkuman lengkap langkah-langkah yang kita lakukan untuk memperbaiki Hoppscotch. | |
| 7 | + | ||
| 8 | + | --- | |
| 9 | + | ||
| 10 | + | ### 🔍 **STEP 1: Identifikasi Masalah Awal** | |
| 11 | + | ||
| 12 | + | **Gejala:** | |
| 13 | + | - Co-worker tidak bisa load workspace list di Hoppscotch (loading terus) | |
| 14 | + | - Error di log: `502 Bad Gateway` | |
| 15 | + | ||
| 16 | + | **Diagnosa:** | |
| 17 | + | ```bash | |
| 18 | + | # Cek log container hoppscotch | |
| 19 | + | docker logs --tail=100 48fc01c8f9a2 2>&1 | grep -i error | |
| 20 | + | ``` | |
| 21 | + | ||
| 22 | + | **Hasil:** | |
| 23 | + | ``` | |
| 24 | + | dial tcp [::1]:8080: connect: connection refused | |
| 25 | + | ``` | |
| 26 | + | → Caddy (reverse proxy) tidak bisa konek ke backend service. | |
| 27 | + | ||
| 28 | + | --- | |
| 29 | + | ||
| 30 | + | ### 🔍 **STEP 2: Cek Status Container & Port** | |
| 31 | + | ||
| 32 | + | ```bash | |
| 33 | + | # Cek container yang running | |
| 34 | + | docker ps --filter "publish=8080" | |
| 35 | + | docker ps -a | grep hoppscotch | |
| 36 | + | ``` | |
| 37 | + | ||
| 38 | + | **Hasil:** Container hoppscotch sudah running tapi backend-nya mati. | |
| 39 | + | ||
| 40 | + | **Cek apakah ada yang listen di port 9502:** | |
| 41 | + | ```bash | |
| 42 | + | sudo netstat -tulpn | grep 9502 | |
| 43 | + | ``` | |
| 44 | + | ||
| 45 | + | **Hasil:** `0.0.0.0:9502` → ada port mapping, tapi service di dalamnya mati. | |
| 46 | + | ||
| 47 | + | --- | |
| 48 | + | ||
| 49 | + | ### 🔍 **STEP 3: Cek Log Lengkap Container** | |
| 50 | + | ||
| 51 | + | ```bash | |
| 52 | + | docker logs -f af2efe1a9953 | |
| 53 | + | ``` | |
| 54 | + | ||
| 55 | + | **Dari log terlihat:** | |
| 56 | + | - ✅ Backend server mulai jalan: `Backend Server | Port: 8080` | |
| 57 | + | - ✅ Semua route terdaftar: `/graphql`, `/ping`, `/auth`, dll. | |
| 58 | + | - ✅ Ada request sukses: `POST /graphql 200` | |
| 59 | + | - ❌ Tapi Caddy masih error: `dial tcp [::1]:8080: connection refused` | |
| 60 | + | ||
| 61 | + | **Kesimpulan:** Backend jalan di `127.0.0.1:8080`, tapi Caddy coba pake `localhost:8080` (IPv6 `::1`). | |
| 62 | + | ||
| 63 | + | --- | |
| 64 | + | ||
| 65 | + | ### 🔍 **STEP 4: Cek Konfigurasi Caddy** | |
| 66 | + | ||
| 67 | + | ```bash | |
| 68 | + | # Masuk ke container | |
| 69 | + | docker exec -it af2efe1a9953 sh | |
| 70 | + | ||
| 71 | + | # Lihat konfigurasi Caddy | |
| 72 | + | cat /etc/caddy/aio-subpath-access.Caddyfile | |
| 73 | + | ``` | |
| 74 | + | ||
| 75 | + | **Isi Caddyfile:** | |
| 76 | + | ``` | |
| 77 | + | handle_path /backend* { | |
| 78 | + | reverse_proxy localhost:8080 # <-- MASALAH: pake localhost (IPv6) | |
| 79 | + | } | |
| 80 | + | ``` | |
| 81 | + | ||
| 82 | + | --- | |
| 83 | + | ||
| 84 | + | ### 🔧 **STEP 5: Perbaiki Konfigurasi Caddy** | |
| 85 | + | ||
| 86 | + | **Ganti `localhost` menjadi `127.0.0.1` (IPv4):** | |
| 87 | + | ||
| 88 | + | ```bash | |
| 89 | + | docker exec af2efe1a9953 sed -i 's/localhost:8080/127.0.0.1:8080/g' /etc/caddy/aio-subpath-access.Caddyfile | |
| 90 | + | ``` | |
| 91 | + | ||
| 92 | + | **Verifikasi:** | |
| 93 | + | ```bash | |
| 94 | + | docker exec af2efe1a9953 cat /etc/caddy/aio-subpath-access.Caddyfile | grep reverse_proxy | |
| 95 | + | ``` | |
| 96 | + | **Hasil:** | |
| 97 | + | ``` | |
| 98 | + | reverse_proxy 127.0.0.1:8080 | |
| 99 | + | ``` | |
| 100 | + | ||
| 101 | + | --- | |
| 102 | + | ||
| 103 | + | ### 🔧 **STEP 6: Restart Container** | |
| 104 | + | ||
| 105 | + | ```bash | |
| 106 | + | docker restart af2efe1a9953 | |
| 107 | + | ||
| 108 | + | # Tunggu beberapa detik | |
| 109 | + | sleep 10 | |
| 110 | + | ``` | |
| 111 | + | ||
| 112 | + | --- | |
| 113 | + | ||
| 114 | + | ### 🔧 **STEP 7: Update Konfigurasi Nginx Host** | |
| 115 | + | ||
| 116 | + | **Edit Nginx:** | |
| 117 | + | ```bash | |
| 118 | + | sudo nano /etc/nginx/sites-available/hoppscotch | |
| 119 | + | ``` | |
| 120 | + | ||
| 121 | + | **Tambahkan location /backend/:** | |
| 122 | + | ```nginx | |
| 123 | + | location /backend/ { | |
| 124 | + | proxy_pass http://127.0.0.1:9500/backend/; # Lewat Caddy di container | |
| 125 | + | proxy_set_header Host $host; | |
| 126 | + | proxy_set_header X-Real-IP $remote_addr; | |
| 127 | + | proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| 128 | + | proxy_set_header X-Forwarded-Proto $scheme; | |
| 129 | + | ||
| 130 | + | # WebSocket support (penting untuk Hoppscotch) | |
| 131 | + | proxy_http_version 1.1; | |
| 132 | + | proxy_set_header Upgrade $http_upgrade; | |
| 133 | + | proxy_set_header Connection "upgrade"; | |
| 134 | + | } | |
| 135 | + | ``` | |
| 136 | + | ||
| 137 | + | **Test & Reload:** | |
| 138 | + | ```bash | |
| 139 | + | sudo nginx -t | |
| 140 | + | sudo systemctl reload nginx | |
| 141 | + | ``` | |
| 142 | + | ||
| 143 | + | --- | |
| 144 | + | ||
| 145 | + | ### ✅ **STEP 8: Test Endpoint** | |
| 146 | + | ||
| 147 | + | **Test dari host (seharusnya 400 - CSRF error, bukan 502):** | |
| 148 | + | ```bash | |
| 149 | + | curl -v https://hoppscotch.konstruksi.ai/backend/graphql | |
| 150 | + | ``` | |
| 151 | + | ||
| 152 | + | **Hasil:** | |
| 153 | + | ``` | |
| 154 | + | < HTTP/2 400 | |
| 155 | + | < content-type: application/json | |
| 156 | + | {"errors":[{"message":"This operation has been blocked as a potential Cross-Site Request Forgery (CSRF)..."}]} | |
| 157 | + | ``` | |
| 158 | + | ✅ **SUKSES!** Response 400 = backend sudah jalan. | |
| 159 | + | ||
| 160 | + | --- | |
| 161 | + | ||
| 162 | + | ### ✅ **STEP 9: Test dengan Request Valid** | |
| 163 | + | ||
| 164 | + | ```bash | |
| 165 | + | curl -X POST https://hoppscotch.konstruksi.ai/backend/graphql \ | |
| 166 | + | -H "Content-Type: application/json" \ | |
| 167 | + | -d '{"query":"{ __typename }"}' | |
| 168 | + | ``` | |
| 169 | + | ||
| 170 | + | **Hasil:** | |
| 171 | + | ```json | |
| 172 | + | {"data":{"__typename":"Query"}} | |
| 173 | + | ``` | |
| 174 | + | ✅ **Backend benar-benar berfungsi!** | |
| 175 | + | ||
| 176 | + | --- | |
| 177 | + | ||
| 178 | + | ### 🎯 **STEP 10: Verifikasi Hoppscotch di Browser** | |
| 179 | + | ||
| 180 | + | 1. Buka `https://hoppscotch.konstruksi.ai` | |
| 181 | + | 2. Login dengan GitHub | |
| 182 | + | 3. Cek workspace list → **sudah bisa load!** | |
| 183 | + | ||
| 184 | + | --- | |
| 185 | + | ||
| 186 | + | ## 📝 **Ringkasan Root Cause & Fix** | |
| 187 | + | ||
| 188 | + | | Masalah | Penyebab | Solusi | | |
| 189 | + | |---------|----------|--------| | |
| 190 | + | | 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` | | |
| 191 | + | | Nginx 502 | Nginx gak ada konfigurasi `/backend/*` | Tambahkan location /backend/ di Nginx | | |
| 192 | + | | Port mapping | Backend listen di 8080, bukan 3170 | Biarkan mapping `9502:3170` (tidak dipakai) | | |
| 193 | + | ||
| 194 | + | --- | |
| 195 | + | ||
| 196 | + | ## 🚀 **Command Penting yang Digunakan** | |
| 197 | + | ||
| 198 | + | ```bash | |
| 199 | + | # Lihat log error | |
| 200 | + | docker logs --tail=100 <container> 2>&1 | grep -i error | |
| 201 | + | ||
| 202 | + | # Follow log live | |
| 203 | + | docker logs -f <container> | |
| 204 | + | ||
| 205 | + | # Masuk ke container | |
| 206 | + | docker exec -it <container> sh | |
| 207 | + | ||
| 208 | + | # Edit file di container | |
| 209 | + | docker exec <container> sed -i 's/old/new/g' /path/to/file | |
| 210 | + | ||
| 211 | + | # Restart container | |
| 212 | + | docker restart <container> | |
| 213 | + | ||
| 214 | + | # Edit Nginx | |
| 215 | + | sudo nano /etc/nginx/sites-available/hoppscotch | |
| 216 | + | ||
| 217 | + | # Reload Nginx | |
| 218 | + | sudo nginx -t && sudo systemctl reload nginx | |
| 219 | + | ``` | |
| 220 | + | ||
| 221 | + | --- | |
| 222 | + | ||
| 223 | + | ## 📌 **Tips Debugging Kedepan** | |
| 224 | + | ||
| 225 | + | 1. **Cek log dulu:** `docker logs --tail=50 <container>` | |
| 226 | + | 2. **Cek dari dalam container:** `docker exec <container> curl http://127.0.0.1:8080/graphql` | |
| 227 | + | 3. **Cek Nginx:** `sudo nginx -t` | |
| 228 | + | 4. **Test endpoint langsung:** `curl -v https://domain.com/path` | |
| 229 | + | ||
| 230 | + | --- | |
| 231 | + | ||
| 232 | + | ## 📊 **Arsitektur Akhir** | |
| 233 | + | ||
| 234 | + | ``` | |
| 235 | + | Browser | |
| 236 | + | ↓ | |
| 237 | + | https://hoppscotch.konstruksi.ai | |
| 238 | + | ↓ | |
| 239 | + | Nginx (Host) | |
| 240 | + | ├── / → http://127.0.0.1:9500 (Caddy → Frontend) | |
| 241 | + | └── /backend/* → http://127.0.0.1:9500/backend/* (Caddy → Backend) | |
| 242 | + | ↓ | |
| 243 | + | Container: hoppscotch (af2efe1a9953) | |
| 244 | + | ├── Caddy (port 9500) | |
| 245 | + | │ └── /backend/* → reverse_proxy 127.0.0.1:8080 | |
| 246 | + | └── Backend Server (port 8080) | |
| 247 | + | └── /graphql, /ping, /auth, dll. | |
| 248 | + | ``` | |
| 249 | + | ||
| 250 | + | --- | |
| 251 | + | ||
| 252 | + | ## ✅ **Status Akhir** | |
| 253 | + | ||
| 254 | + | - ✅ Frontend Hoppscotch jalan di `https://hoppscotch.konstruksi.ai` | |
| 255 | + | - ✅ Backend GraphQL jalan di `https://hoppscotch.konstruksi.ai/backend/graphql` | |
| 256 | + | - ✅ WebSocket support untuk realtime | |
| 257 | + | - ✅ Co-worker bisa login dan load workspace list | |
| 258 | + | ``` | |
Newer
Older