2.4 KiB
2.4 KiB
🚨 INSTRUKSI PERBAIKAN CORS - WAJIB DILAKUKAN
⚠️ MASALAH SAAT INI
- Browser tidak bisa login karena CORS error
- Request OPTIONS (preflight) return 400 Bad Request
- Server API belum memiliki CORS handler
✅ SOLUSI: Upload File dengan CORS Handler
LANGKAH 1: Buka File yang Sudah Diperbaiki
File berikut sudah diperbaiki dan siap digunakan:
api/auth/login.php✅api/dashboard/summary.php✅api/dashboard/chart.php✅api/dashboard/chart_monthly.php✅api/dashboard/events.php✅
LANGKAH 2: Copy Kode CORS Handler
Setiap file sudah memiliki CORS handler di baris paling atas:
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS");
header("Access-Control-Allow-Headers: Content-Type, Authorization, X-API-KEY");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
http_response_code(200);
exit;
}
LANGKAH 3: Upload ke Server API
OPSI A: Upload File Lengkap
- Buka file
api/auth/login.phpdi folder lokal - Copy seluruh isinya
- Upload/replace file di server:
/retribusi/v1/api/auth/login.php - Ulangi untuk semua file endpoint lainnya
OPSI B: Tambahkan CORS Handler ke File yang Sudah Ada
- Buka file API yang sudah ada di server
- Tambahkan kode CORS handler di BARIS PALING ATAS (sebelum require/include apapun)
- Pastikan kode CORS dieksekusi sebelum logic lainnya
LANGKAH 4: Test
Setelah upload, test dengan:
# Test OPTIONS (harus return 200)
curl -X OPTIONS https://api.btekno.cloud/retribusi/v1/api/auth/login.php -i
# Test POST (harus berhasil)
curl -X POST https://api.btekno.cloud/retribusi/v1/api/auth/login.php \
-H "Content-Type: application/json" \
-H "X-API-KEY: RETRIBUSI-DASHBOARD-KEY" \
-d '{"username":"admin","password":"dodolgarut"}'
✅ HASIL YANG DIHARAPKAN
Setelah upload:
- ✅
curl -X OPTIONS→ HTTP 200 OK - ✅ Browser bisa login tanpa error CORS
- ✅ Frontend berfungsi normal
📋 CHECKLIST
- File
api/auth/login.phpsudah di-upload ke server - CORS handler ada di baris paling atas
- OPTIONS request return HTTP 200
- Test login dari browser berhasil
⚠️ PENTING
- CORS handler HARUS di baris paling atas
- CORS handler HARUS dieksekusi sebelum require/include
- CORS handler HARUS dieksekusi sebelum logic auth
- Setelah upload, clear cache browser jika perlu