Move index.php dari root ke public/ - running directory sekarang di public

This commit is contained in:
mwpn
2025-12-18 11:40:02 +07:00
parent 8c2419d1a7
commit ef51cf96a2
2 changed files with 39 additions and 37 deletions

View File

@@ -6,8 +6,8 @@ Frontend aplikasi Retribusi BAPENDA Kabupaten Garut.
``` ```
retribusi (frontend)/ retribusi (frontend)/
├── index.php # Login page ├── public/ # Document root (running directory)
├── public/ │ ├── index.php # Login page
│ ├── dashboard/ │ ├── dashboard/
│ │ ├── dashboard.html # Dashboard utama │ │ ├── dashboard.html # Dashboard utama
│ │ ├── event.html # Halaman event logs │ │ ├── event.html # Halaman event logs
@@ -21,7 +21,6 @@ retribusi (frontend)/
│ │ ├── dashboard.js # Dashboard logic │ │ ├── dashboard.js # Dashboard logic
│ │ ├── charts.js # Chart.js helpers │ │ ├── charts.js # Chart.js helpers
│ │ └── realtime.js # Realtime SSE client │ │ └── realtime.js # Realtime SSE client
│ └── index.php
└── api/ # Legacy API endpoints (deprecated) └── api/ # Legacy API endpoints (deprecated)
``` ```
@@ -50,8 +49,9 @@ File `public/dashboard/js/config.js` mengatur:
## Development ## Development
1. Pastikan backend API sudah running 1. Pastikan backend API sudah running
2. Buka `index.php` untuk login 2. Set document root ke folder `public/`
3. Akses dashboard di `public/dashboard/dashboard.html` 3. Buka `index.php` untuk login (atau akses root `/`)
4. Akses dashboard di `dashboard/dashboard.html`
## Production ## Production

View File

@@ -1,5 +1,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="id"> <html lang="id">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -20,6 +21,7 @@
} }
</script> </script>
</head> </head>
<body class="font-outfit bg-gray-50 min-h-screen flex items-center justify-center p-4"> <body class="font-outfit bg-gray-50 min-h-screen flex items-center justify-center p-4">
<div class="w-full max-w-md"> <div class="w-full max-w-md">
<div class="bg-white rounded-lg shadow-lg p-8 md:p-10 border border-gray-200"> <div class="bg-white rounded-lg shadow-lg p-8 md:p-10 border border-gray-200">
@@ -30,53 +32,51 @@
<form id="loginForm" class="space-y-5"> <form id="loginForm" class="space-y-5">
<div> <div>
<label for="username" class="block text-sm font-medium text-gray-700 mb-2">Username</label> <label for="username" class="block text-sm font-medium text-gray-700 mb-2">Username</label>
<input <input
type="text" type="text"
id="username" id="username"
name="username" name="username"
required required
autocomplete="username" autocomplete="username"
class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-gray-900 focus:border-transparent transition-all text-gray-900 placeholder-gray-400" class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-gray-900 focus:border-transparent transition-all text-gray-900 placeholder-gray-400"
placeholder="Masukkan username" placeholder="Masukkan username">
>
</div> </div>
<div> <div>
<label for="password" class="block text-sm font-medium text-gray-700 mb-2">Password</label> <label for="password" class="block text-sm font-medium text-gray-700 mb-2">Password</label>
<input <input
type="password" type="password"
id="password" id="password"
name="password" name="password"
required required
autocomplete="current-password" autocomplete="current-password"
class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-gray-900 focus:border-transparent transition-all text-gray-900 placeholder-gray-400" class="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-gray-900 focus:border-transparent transition-all text-gray-900 placeholder-gray-400"
placeholder="Masukkan password" placeholder="Masukkan password">
>
</div> </div>
<div id="errorMessage" class="hidden bg-red-50 border border-red-200 text-red-700 p-3 rounded-lg text-sm"></div> <div id="errorMessage" class="hidden bg-red-50 border border-red-200 text-red-700 p-3 rounded-lg text-sm"></div>
<button <button
type="submit" type="submit"
class="w-full bg-gray-900 text-white font-medium py-2.5 px-6 rounded-lg hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 transition-all duration-200" class="w-full bg-gray-900 text-white font-medium py-2.5 px-6 rounded-lg hover:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-gray-900 focus:ring-offset-2 transition-all duration-200">
>
Login Login
</button> </button>
</form> </form>
</div> </div>
</div> </div>
<!-- Pakai API & Auth dari public/dashboard/js --> <!-- Pakai API & Auth dari dashboard/js -->
<script type="module"> <script type="module">
import { Auth } from './public/dashboard/js/auth.js'; import {
Auth
} from './dashboard/js/auth.js';
window.Auth = Auth; window.Auth = Auth;
// Jika sudah login, langsung arahkan ke dashboard utama (public/dashboard) // Jika sudah login, langsung arahkan ke dashboard
// Cek dulu apakah kita sudah di dashboard untuk menghindari redirect loop // Cek dulu apakah kita sudah di dashboard untuk menghindari redirect loop
// Gunakan check yang lebih spesifik untuk mencegah loop
(function() { (function() {
// Cek apakah ini benar-benar halaman index.php (bukan dashboard) // Cek apakah ini benar-benar halaman index.php (bukan dashboard)
const currentPath = window.location.pathname; const currentPath = window.location.pathname;
const isIndexPage = currentPath.endsWith('index.php') || currentPath.endsWith('/') || currentPath === '/'; const isIndexPage = currentPath.endsWith('index.php') || currentPath.endsWith('/') || currentPath === '/';
const isDashboardPage = currentPath.includes('dashboard.html') || currentPath.includes('event.html') || currentPath.includes('settings.html'); const isDashboardPage = currentPath.includes('dashboard.html') || currentPath.includes('event.html') || currentPath.includes('settings.html');
// Hanya redirect jika: // Hanya redirect jika:
// 1. User sudah authenticated // 1. User sudah authenticated
// 2. Kita di index page (bukan dashboard) // 2. Kita di index page (bukan dashboard)
@@ -85,7 +85,7 @@
const redirectKey = 'auth_redirect_done'; const redirectKey = 'auth_redirect_done';
if (!sessionStorage.getItem(redirectKey)) { if (!sessionStorage.getItem(redirectKey)) {
sessionStorage.setItem(redirectKey, '1'); sessionStorage.setItem(redirectKey, '1');
window.location.href = 'public/dashboard/dashboard.html'; window.location.href = 'dashboard/dashboard.html';
return; return;
} }
} }
@@ -95,22 +95,24 @@
e.preventDefault(); e.preventDefault();
const errorDiv = document.getElementById('errorMessage'); const errorDiv = document.getElementById('errorMessage');
errorDiv.classList.add('hidden'); errorDiv.classList.add('hidden');
const username = document.getElementById('username').value.trim(); const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value; const password = document.getElementById('password').value;
const submitBtn = e.target.querySelector('button[type="submit"]'); const submitBtn = e.target.querySelector('button[type="submit"]');
submitBtn.disabled = true; submitBtn.disabled = true;
submitBtn.textContent = 'Memproses...'; submitBtn.textContent = 'Memproses...';
try { try {
const { apiLogin } = await import('./public/dashboard/js/api.js'); const {
apiLogin
} = await import('./dashboard/js/api.js');
const response = await apiLogin(username, password); const response = await apiLogin(username, password);
if (response.token) { if (response.token) {
Auth.saveToken(response.token); Auth.saveToken(response.token);
Auth.saveUser(response.user); Auth.saveUser(response.user);
// Arahkan ke dashboard utama (public/dashboard) // Arahkan ke dashboard
window.location.href = 'public/dashboard/dashboard.html'; window.location.href = 'dashboard/dashboard.html';
} else { } else {
throw new Error('Response tidak berisi token.'); throw new Error('Response tidak berisi token.');
} }
@@ -123,6 +125,6 @@
}); });
</script> </script>
</body> </body>
</html> </html>