2025-12-18 11:21:40 +07:00
|
|
|
// public/dashboard/js/config.js
|
|
|
|
|
// Konfigurasi API Base URL untuk frontend
|
|
|
|
|
|
2026-01-01 23:38:42 +07:00
|
|
|
// 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
|
2025-12-18 11:21:40 +07:00
|
|
|
function getApiBaseUrl() {
|
2026-01-01 23:38:42 +07:00
|
|
|
// 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';
|
|
|
|
|
}
|
2025-12-18 11:21:40 +07:00
|
|
|
|
2026-01-01 23:38:42 +07:00
|
|
|
// 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 });
|
2025-12-18 11:21:40 +07:00
|
|
|
|
2026-01-01 23:38:42 +07:00
|
|
|
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
|
2025-12-18 11:21:40 +07:00
|
|
|
|
2026-01-01 23:38:42 +07:00
|
|
|
console.log('[Config] Is Local:', isLocal);
|
2025-12-18 11:21:40 +07:00
|
|
|
|
2026-01-01 23:38:42 +07:00
|
|
|
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;
|
|
|
|
|
}
|
2025-12-18 11:21:40 +07:00
|
|
|
}
|
|
|
|
|
|
2026-01-01 23:38:42 +07:00
|
|
|
// Default: API produksi
|
|
|
|
|
console.log('[Config] Using production API');
|
2025-12-18 11:21:40 +07:00
|
|
|
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);
|
2026-01-01 23:38:42 +07:00
|
|
|
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.'));
|
2025-12-18 11:21:40 +07:00
|
|
|
}
|
|
|
|
|
|