File size: 2,048 Bytes
babf3f3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
/**
* RAG μ±λ΄ ν΄λΌμ΄μΈνΈ - κ³΅ν΅ κΈ°λ₯
*/
document.addEventListener('DOMContentLoaded', function() {
// API κΈ°λ³Έ URL
const API_BASE_URL = window.location.origin;
// μν νμΈ ν¨μ
async function checkApiStatus() {
try {
const response = await fetch(`${API_BASE_URL}/api/status`);
const data = await response.json();
if (data.ready) {
// API μλ² μ€λΉ μλ£
console.log('API μλ² μ€λΉ μλ£');
// λ‘λ© νμ΄μ§μμ μλ€λ©΄ νμΌλ‘ 리λλ μ
if (window.location.pathname === '/loading') {
window.location.href = '/';
}
return true;
} else {
// API μλ² μ€λΉ μ€
console.log('API μλ² μ΄κΈ°ν μ€...');
// λ‘λ© νμ΄μ§κ° μλλ©΄ λ‘λ© νμ΄μ§λ‘ 리λλ μ
if (window.location.pathname !== '/loading') {
window.location.href = '/loading';
}
return false;
}
} catch (err) {
console.error('API μλ² μν νμΈ μ€ν¨:', err);
// μ°κ²° μ€λ₯ μ μ²λ¦¬
const statusDisplay = document.getElementById('apiStatusDisplay');
if (statusDisplay) {
statusDisplay.innerHTML = `
<div class="alert alert-danger">
<i class="fas fa-exclamation-triangle me-2"></i>
API μλ²μ μ°κ²°ν μ μμ΅λλ€. μλ²κ° μ€ν μ€μΈμ§ νμΈνμΈμ.
</div>
`;
}
return false;
}
}
// νμ΄μ§ λ‘λ μ API μν νμΈ
checkApiStatus();
// μ£ΌκΈ°μ μΌλ‘ API μν νμΈ (10μ΄λ§λ€)
setInterval(checkApiStatus, 10000);
});
|