File size: 2,548 Bytes
6dec88d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
    <title>API Test</title>
    <style>
        body { font-family: Arial; padding: 20px; background: #1a1a1a; color: #fff; }
        button { padding: 10px 20px; margin: 10px; background: #c8f04e; border: none; cursor: pointer; font-size: 16px; }
        pre { background: #2a2a2a; padding: 15px; border-radius: 8px; overflow-x: auto; }
        .success { color: #4ade80; }
        .error { color: #ff4d4d; }
    </style>
</head>
<body>
    <h1>🧪 Moharek API Test</h1>
    
    <button onclick="testAPI()">Test API Connection</button>
    <button onclick="testLogin()">Test Login</button>
    
    <h3>Results:</h3>
    <pre id="results"></pre>

    <script>
        const API = window.location.origin + '/api';
        
        document.getElementById('results').textContent = 
            'Origin: ' + window.location.origin + '\n' +
            'API URL: ' + API + '\n' +
            'Timestamp: ' + new Date().toISOString();

        async function testAPI() {
            const results = document.getElementById('results');
            results.textContent += '\n\n--- Testing API ---\n';
            
            try {
                const res = await fetch(API + '/health');
                results.textContent += 'Health Status: ' + res.status + '\n';
                const data = await res.json();
                results.textContent += 'Health Data: ' + JSON.stringify(data, null, 2) + '\n';
            } catch (err) {
                results.textContent += 'ERROR: ' + err.message + '\n';
            }
        }

        async function testLogin() {
            const results = document.getElementById('results');
            results.textContent += '\n\n--- Testing Login ---\n';
            
            try {
                const res = await fetch(API + '/users/login', {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify({ 
                        email: 'admin@moharek.com', 
                        password: 'admin123' 
                    })
                });
                results.textContent += 'Login Status: ' + res.status + '\n';
                const data = await res.json();
                results.textContent += 'Login Data: ' + JSON.stringify(data, null, 2) + '\n';
            } catch (err) {
                results.textContent += 'ERROR: ' + err.message + '\n';
            }
        }

        // Auto test on load
        setTimeout(testAPI, 500);
    </script>
</body>
</html>