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);
});