forked from izu/student-web-if-development-kit
refactor: Perbaiki Proxy Pipeline dan simplify dashboard configuration
This commit is contained in:
+18
-47
@@ -77,12 +77,6 @@
|
||||
debugLogs: false,
|
||||
dashboardRuntimeFetch: 'always',
|
||||
dashboardApiUrl: 'api/dashboard',
|
||||
dashboardTargetUrl: 'https://dashboard.informatika.untan.ac.id/index.php?penelitian',
|
||||
dashboardProxyTemplates: [
|
||||
'https://api.codetabs.com/v1/proxy?quest={{url}}',
|
||||
'https://api.allorigins.win/get?url={{url}}&ts={{ts}}',
|
||||
'https://thingproxy.freeboard.io/fetch/{{rawUrl}}'
|
||||
]
|
||||
};
|
||||
</script>
|
||||
<!-- RODA_DASHBOARD_DATA -->
|
||||
@@ -1662,56 +1656,33 @@
|
||||
}
|
||||
|
||||
let lastError = null;
|
||||
|
||||
if (isDashboardRuntimeFetchAllowed()) {
|
||||
const dashboardApiUrl = window.APP_CONFIG?.dashboardApiUrl?.trim();
|
||||
|
||||
if (dashboardApiUrl) {
|
||||
try {
|
||||
const rows = await fetchProxyRows(dashboardApiUrl);
|
||||
applyDashboardRows(rows);
|
||||
return;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback ke data yang di-embed saat build jika runtime fetch gagal atau dinonaktifkan
|
||||
const embeddedHtml = readEmbeddedDashboardHtml();
|
||||
if (embeddedHtml) {
|
||||
try {
|
||||
applyDashboardRows(parseDashboardRows(embeddedHtml));
|
||||
return;
|
||||
} catch (error) {
|
||||
lastError = error;
|
||||
lastError = lastError || error;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isDashboardRuntimeFetchAllowed()) {
|
||||
renderRisetFeedback('Pemuatan Data Gagal', getDashboardErrorMessage(lastError || new Error('DASHBOARD_RUNTIME_FETCH_DISABLED')), 'Coba Lagi', 'fetchDashboardData()');
|
||||
return;
|
||||
}
|
||||
|
||||
const targetUrl = window.APP_CONFIG?.dashboardTargetUrl?.trim();
|
||||
const dashboardApiUrl = window.APP_CONFIG?.dashboardApiUrl?.trim();
|
||||
const proxyTemplates = Array.isArray(window.APP_CONFIG?.dashboardProxyTemplates)
|
||||
? window.APP_CONFIG.dashboardProxyTemplates.filter(Boolean)
|
||||
: [];
|
||||
|
||||
const proxyServers = dashboardApiUrl ? [() => dashboardApiUrl] : [];
|
||||
|
||||
if (targetUrl) {
|
||||
proxyTemplates.forEach((template) => {
|
||||
proxyServers.push((url) => template
|
||||
.replaceAll('{{url}}', encodeURIComponent(url))
|
||||
.replaceAll('{{rawUrl}}', url)
|
||||
.replaceAll('{{ts}}', String(Date.now())));
|
||||
});
|
||||
}
|
||||
|
||||
if (!proxyServers.length) {
|
||||
renderRisetFeedback('Pemuatan Data Gagal', getDashboardErrorMessage(new Error('DASHBOARD_PROXY_NOT_CONFIGURED')), 'Coba Lagi', 'fetchDashboardData()');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const proxyUrls = proxyServers.map((getProxyUrl) => getProxyUrl(targetUrl));
|
||||
const rows = await Promise.any(proxyUrls.map((proxyUrl) => fetchProxyRows(proxyUrl)));
|
||||
applyDashboardRows(rows);
|
||||
return;
|
||||
} catch (error) {
|
||||
lastError = error instanceof AggregateError && error.errors?.length
|
||||
? error.errors[error.errors.length - 1]
|
||||
: error;
|
||||
}
|
||||
|
||||
// Jika semua proxy gagal
|
||||
renderRisetFeedback('Pemuatan Data Gagal', getDashboardErrorMessage(lastError), 'Coba Lagi', 'fetchDashboardData()');
|
||||
renderRisetFeedback('Pemuatan Data Gagal', getDashboardErrorMessage(lastError || new Error('DASHBOARD_RUNTIME_FETCH_DISABLED')), 'Coba Lagi', 'fetchDashboardData()');
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user