jeongsoo's picture
Add application file
babf3f3
/**
* 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);
});