Fix ERR_TOO_MANY_REDIRECTS: hapus public/index.php dan tambah guard untuk prevent redirect loop

This commit is contained in:
mwpn
2025-12-18 11:34:20 +07:00
parent 90d0d1a761
commit 28ddcc71ff
6 changed files with 17 additions and 9 deletions

View File

@@ -43,6 +43,7 @@ retribusi (frontend)/
## Konfigurasi ## Konfigurasi
File `public/dashboard/js/config.js` mengatur: File `public/dashboard/js/config.js` mengatur:
- API Base URL (auto-detect local/production) - API Base URL (auto-detect local/production)
- API Key untuk autentikasi - API Key untuk autentikasi
@@ -55,12 +56,14 @@ File `public/dashboard/js/config.js` mengatur:
## Production ## Production
Deploy ke web server (Apache/Nginx) dengan konfigurasi: Deploy ke web server (Apache/Nginx) dengan konfigurasi:
- Base URL: sesuai dengan domain production - Base URL: sesuai dengan domain production
- API Base URL: otomatis terdeteksi dari hostname - API Base URL: otomatis terdeteksi dari hostname
### Update di Server Production ### Update di Server Production
**Cara 1: Menggunakan Script (Recommended)** **Cara 1: Menggunakan Script (Recommended)**
```bash ```bash
# Linux/Unix # Linux/Unix
cd /path/to/retribusi-frontend cd /path/to/retribusi-frontend
@@ -72,17 +75,20 @@ pull.bat
``` ```
**Cara 2: Command Langsung (Sekali Jalan)** **Cara 2: Command Langsung (Sekali Jalan)**
```bash ```bash
cd /path/to/retribusi-frontend && git stash && git pull origin main && git stash pop cd /path/to/retribusi-frontend && git stash && git pull origin main && git stash pop
``` ```
**Cara 3: Manual** **Cara 3: Manual**
```bash ```bash
cd /path/to/retribusi-frontend cd /path/to/retribusi-frontend
git pull origin main git pull origin main
``` ```
**Fix Dubious Ownership Error (jika muncul)** **Fix Dubious Ownership Error (jika muncul)**
```bash ```bash
# Tambahkan directory ke safe.directory # Tambahkan directory ke safe.directory
git config --global --add safe.directory /www/wwwroot/retribusi.btekno.cloud/retribusi git config --global --add safe.directory /www/wwwroot/retribusi.btekno.cloud/retribusi
@@ -90,4 +96,3 @@ git config --global --add safe.directory /www/wwwroot/retribusi.btekno.cloud/ret
# Atau gunakan script pull.sh yang sudah auto-fix # Atau gunakan script pull.sh yang sudah auto-fix
bash pull.sh bash pull.sh
``` ```

View File

@@ -69,7 +69,9 @@
window.Auth = Auth; window.Auth = Auth;
// Jika sudah login, langsung arahkan ke dashboard utama (public/dashboard) // Jika sudah login, langsung arahkan ke dashboard utama (public/dashboard)
if (Auth.isAuthenticated()) { // Cek dulu apakah kita sudah di dashboard untuk menghindari redirect loop
const currentPath = window.location.pathname;
if (Auth.isAuthenticated() && !currentPath.includes('dashboard.html')) {
window.location.href = 'public/dashboard/dashboard.html'; window.location.href = 'public/dashboard/dashboard.html';
} }

View File

@@ -40,7 +40,11 @@ async function apiRequest(path, options = {}) {
// Unauthorized → clear token & redirect to login // Unauthorized → clear token & redirect to login
localStorage.removeItem('token'); localStorage.removeItem('token');
localStorage.removeItem('user'); localStorage.removeItem('user');
// Cek apakah sudah di login page untuk menghindari redirect loop
const currentPath = window.location.pathname;
if (!currentPath.includes('index.php')) {
window.location.href = '../index.php'; window.location.href = '../index.php';
}
throw new Error('Unauthorized'); throw new Error('Unauthorized');
} }

View File

@@ -75,7 +75,9 @@ async function handleLoginSubmit(event) {
document.addEventListener('DOMContentLoaded', () => { document.addEventListener('DOMContentLoaded', () => {
const form = document.getElementById('login-form'); const form = document.getElementById('login-form');
if (form) { if (form) {
if (Auth.isAuthenticated()) { // Cek apakah sudah authenticated dan belum di dashboard untuk menghindari redirect loop
const currentPath = window.location.pathname;
if (Auth.isAuthenticated() && !currentPath.includes('dashboard')) {
window.location.href = 'dashboard.html'; window.location.href = 'dashboard.html';
return; return;
} }

View File

@@ -1,5 +0,0 @@
<?php
// Redirect ke login page di root
header('Location: ../index.php');
exit;

BIN
retribusi (frontend).zip Normal file

Binary file not shown.