Files
Retribusi/public/dashboard/js/config.js

67 lines
2.4 KiB
JavaScript
Raw Normal View History

// public/dashboard/js/config.js
// Konfigurasi API Base URL untuk frontend
// 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() {
// 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';
}
// 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';
}
// Export config
export const API_CONFIG = {
BASE_URL: getApiBaseUrl(),
API_KEY: 'POKOKEIKISEKOYOLO', // Sesuaikan dengan RETRIBUSI_API_KEY di backend
TIMEOUT: 30000 // 30 detik
};
// 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.'));
}