Fix: tambah instruksi untuk jalankan backend dengan router.php
This commit is contained in:
@@ -34,12 +34,21 @@ http://localhost/index.html
|
|||||||
|
|
||||||
### Opsi 3: Gunakan PHP Built-in Server
|
### Opsi 3: Gunakan PHP Built-in Server
|
||||||
|
|
||||||
|
**Frontend:**
|
||||||
```bash
|
```bash
|
||||||
cd "C:\laragon\www\RETRIBUSI_BAPENDA\retribusi (frontend)\public"
|
cd "C:\laragon\www\RETRIBUSI_BAPENDA\retribusi (frontend)\public"
|
||||||
php -S localhost:8080
|
php -S localhost:8080
|
||||||
```
|
```
|
||||||
|
|
||||||
Akses: `http://localhost:8080/index.html`
|
**Backend API (PENTING - harus dengan router.php):**
|
||||||
|
```bash
|
||||||
|
cd "C:\laragon\www\RETRIBUSI_BAPENDA\api-btekno\public"
|
||||||
|
php -S localhost:8000 router.php
|
||||||
|
```
|
||||||
|
|
||||||
|
**Akses:**
|
||||||
|
- Frontend: `http://localhost:8080/index.html`
|
||||||
|
- Backend API: `http://localhost:8000` (dengan router.php)
|
||||||
|
|
||||||
## Konfigurasi API
|
## Konfigurasi API
|
||||||
|
|
||||||
|
|||||||
102
SETUP_LOCAL_FIX.md
Normal file
102
SETUP_LOCAL_FIX.md
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
# Fix: Failed to fetch di Localhost
|
||||||
|
|
||||||
|
## Masalah
|
||||||
|
|
||||||
|
Error: "Failed to fetch" saat mengakses `http://localhost:8080/`
|
||||||
|
|
||||||
|
Backend API error:
|
||||||
|
```
|
||||||
|
[404]: OPTIONS /auth/v1/login - No such file or directory
|
||||||
|
```
|
||||||
|
|
||||||
|
## Penyebab
|
||||||
|
|
||||||
|
PHP built-in server dijalankan **TANPA router.php**, sehingga routing tidak bekerja.
|
||||||
|
|
||||||
|
## Solusi
|
||||||
|
|
||||||
|
### 1. Jalankan Backend API dengan Router
|
||||||
|
|
||||||
|
**SALAH** (yang menyebabkan error):
|
||||||
|
```bash
|
||||||
|
cd api-btekno
|
||||||
|
php -S localhost:8000
|
||||||
|
```
|
||||||
|
|
||||||
|
**BENAR** (yang harus dilakukan):
|
||||||
|
```bash
|
||||||
|
cd api-btekno/public
|
||||||
|
php -S localhost:8000 router.php
|
||||||
|
```
|
||||||
|
|
||||||
|
File `router.php` diperlukan untuk handle routing seperti `/auth/v1/login`.
|
||||||
|
|
||||||
|
### 2. Jalankan Frontend
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cd "retribusi (frontend)/public"
|
||||||
|
php -S localhost:8080
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Test Backend API
|
||||||
|
|
||||||
|
Buka browser dan akses:
|
||||||
|
```
|
||||||
|
http://localhost:8000/health
|
||||||
|
```
|
||||||
|
|
||||||
|
Harusnya return: `{"status":"ok","time":...}`
|
||||||
|
|
||||||
|
Jika masih 404, berarti router.php tidak bekerja.
|
||||||
|
|
||||||
|
### 4. Cek Config Frontend
|
||||||
|
|
||||||
|
File `public/dashboard/js/config.js` harus return:
|
||||||
|
```javascript
|
||||||
|
return 'http://localhost:8000';
|
||||||
|
```
|
||||||
|
|
||||||
|
## Quick Start Script
|
||||||
|
|
||||||
|
Buat file `start-local.bat` di root project:
|
||||||
|
|
||||||
|
```batch
|
||||||
|
@echo off
|
||||||
|
echo Starting Backend API...
|
||||||
|
start "Backend API" cmd /k "cd api-btekno\public && php -S localhost:8000 router.php"
|
||||||
|
|
||||||
|
timeout /t 2
|
||||||
|
|
||||||
|
echo Starting Frontend...
|
||||||
|
start "Frontend" cmd /k "cd retribusi (frontend)\public && php -S localhost:8080"
|
||||||
|
|
||||||
|
echo.
|
||||||
|
echo Backend API: http://localhost:8000
|
||||||
|
echo Frontend: http://localhost:8080
|
||||||
|
echo.
|
||||||
|
pause
|
||||||
|
```
|
||||||
|
|
||||||
|
Jalankan `start-local.bat` untuk start kedua server sekaligus.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### Masih 404 di Backend?
|
||||||
|
|
||||||
|
1. Pastikan menjalankan dari folder `api-btekno/public`
|
||||||
|
2. Pastikan menggunakan `router.php`: `php -S localhost:8000 router.php`
|
||||||
|
3. Cek file `router.php` ada di `api-btekno/public/router.php`
|
||||||
|
|
||||||
|
### Masih "Failed to fetch"?
|
||||||
|
|
||||||
|
1. Buka browser console (F12)
|
||||||
|
2. Cek log `[API] Request:` - pastikan URL benar
|
||||||
|
3. Test backend langsung: `curl http://localhost:8000/health`
|
||||||
|
4. Cek CORS - pastikan backend allow origin `http://localhost:8080`
|
||||||
|
|
||||||
|
### CORS Error?
|
||||||
|
|
||||||
|
Backend sudah ada CORS middleware, tapi pastikan:
|
||||||
|
1. Backend running dengan router.php
|
||||||
|
2. CORS middleware sudah di-register di `public/index.php`
|
||||||
|
|
||||||
Reference in New Issue
Block a user