Fix: Data inconsistency pada transisi tahun/bulan dan setup API lokal untuk testing

- Fix deteksi transisi bulan untuk semua bulan (tidak hanya 1 Januari)
- Perbaikan validasi data dengan threshold 20% untuk transisi bulan/tahun
- Auto-reset chart jika data hourly tidak valid
- Setup force local mode untuk testing API lokal
- Perbaikan normalisasi dan validasi tanggal
- Enhanced logging untuk debugging transisi
This commit is contained in:
BTekno Dev
2026-01-01 23:38:42 +07:00
parent fccda40d72
commit 5e330e931b
6 changed files with 655 additions and 48 deletions

View File

@@ -1,26 +1,47 @@
// public/dashboard/js/config.js
// Konfigurasi API Base URL untuk frontend
// Auto-detect environment berdasarkan hostname
// FORCE LOCAL MODE - Set ke true untuk force menggunakan API lokal
const FORCE_LOCAL_MODE = true; // Set ke false untuk auto-detect
// Auto-detect API Base URL berdasarkan hostname
function getApiBaseUrl() {
const hostname = window.location.hostname;
// Development lokal (Laragon/XAMPP)
if (hostname === 'localhost' || hostname === '127.0.0.1' || hostname.startsWith('192.168.')) {
// Untuk PHP built-in server (port 8000)
// return 'http://localhost:8000';
// Untuk Laragon/Apache (path-based)
// return 'http://localhost/api-btekno/public';
// Untuk Laragon virtual host
// return 'http://api.retribusi.test';
// Default: PHP built-in server
return 'http://localhost:8000';
// Force local mode untuk testing
if (FORCE_LOCAL_MODE) {
console.log('[Config] FORCE_LOCAL_MODE enabled, using local API');
return 'http://localhost/api-btekno/public';
}
// Production
// Jika di localhost atau 127.0.0.1, gunakan API lokal
if (typeof window !== 'undefined') {
const hostname = window.location.hostname;
const port = window.location.port;
const protocol = window.location.protocol;
console.log('[Config] Detecting environment:', { hostname, port, protocol, fullUrl: window.location.href });
const isLocal = hostname === 'localhost' ||
hostname === '127.0.0.1' ||
hostname === '' ||
hostname.startsWith('192.168.') ||
hostname.startsWith('10.') ||
hostname.startsWith('172.') ||
protocol === 'file:'; // File protocol (file://) juga dianggap local
console.log('[Config] Is Local:', isLocal);
if (isLocal) {
// API lokal - sesuaikan dengan konfigurasi server lokal Anda
// Untuk Laragon, biasanya: http://localhost/api-btekno/public
// Atau jika menggunakan PHP built-in server: http://localhost:8000
const localApiUrl = 'http://localhost/api-btekno/public';
console.log('[Config] Using local API:', localApiUrl);
return localApiUrl;
}
}
// Default: API produksi
console.log('[Config] Using production API');
return 'https://api.btekno.cloud';
}
@@ -34,5 +55,12 @@ export const API_CONFIG = {
// Untuk debugging
if (typeof window !== 'undefined') {
console.log('API Base URL:', API_CONFIG.BASE_URL);
console.log('Hostname:', window.location.hostname);
console.log('Is Local:', window.location.hostname === 'localhost' ||
window.location.hostname === '127.0.0.1' ||
window.location.hostname === '' ||
window.location.hostname.startsWith('192.168.') ||
window.location.hostname.startsWith('10.') ||
window.location.hostname.startsWith('172.'));
}