forked from Rathore-Rajpal/Superbot-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api.html
More file actions
130 lines (115 loc) Β· 5.08 KB
/
test-api.html
File metadata and controls
130 lines (115 loc) Β· 5.08 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>API Test - Render Backend</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
.test { margin: 20px 0; padding: 10px; border: 1px solid #ccc; }
.success { background-color: #d4edda; border-color: #c3e6cb; }
.error { background-color: #f8d7da; border-color: #f5c6cb; }
button { padding: 10px 20px; margin: 5px; cursor: pointer; }
.url { font-family: monospace; background: #f8f9fa; padding: 5px; margin: 10px 0; }
</style>
</head>
<body>
<h1>π§ API Connection Test - Render Backend</h1>
<div class="test">
<h3>Backend URL</h3>
<div class="url">https://superbot-animated-ui.onrender.com/api</div>
<p>β
This backend is always running on Render (no need for local server)</p>
</div>
<div class="test">
<h3>Backend Health Check</h3>
<button onclick="testHealth()">Test Health Endpoint</button>
<div id="health-result"></div>
</div>
<div class="test">
<h3>Database Connection Test</h3>
<button onclick="testTasks()">Test Tasks API</button>
<div id="tasks-result"></div>
</div>
<div class="test">
<h3>Finance Data Test</h3>
<button onclick="testFinances()">Test Finances API</button>
<div id="finances-result"></div>
</div>
<script>
const API_BASE = 'https://superbot-animated-ui.onrender.com/api';
async function testHealth() {
const resultDiv = document.getElementById('health-result');
resultDiv.innerHTML = 'π Testing...';
try {
const response = await fetch(`${API_BASE}/health`);
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = `
<div class="success">
β
Health Check PASSED<br>
Status: ${data.status}<br>
Message: ${data.message}<br>
Environment: ${data.environment}<br>
Database: ${data.database.host}<br>
Uptime: ${data.uptime.toFixed(2)}s
</div>
`;
} else {
resultDiv.innerHTML = `<div class="error">β Health Check FAILED: ${response.status}</div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error">β Health Check ERROR: ${error.message}</div>`;
}
}
async function testTasks() {
const resultDiv = document.getElementById('tasks-result');
resultDiv.innerHTML = 'π Testing...';
try {
const response = await fetch(`${API_BASE}/tasks`);
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = `
<div class="success">
β
Tasks API PASSED<br>
Found ${data.length} tasks<br>
First task: ${data[0]?.title || 'No tasks'}<br>
Status: ${data[0]?.status || 'N/A'}
</div>
`;
} else {
resultDiv.innerHTML = `<div class="error">β Tasks API FAILED: ${response.status}</div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error">β Tasks API ERROR: ${error.message}</div>`;
}
}
async function testFinances() {
const resultDiv = document.getElementById('finances-result');
resultDiv.innerHTML = 'π Testing...';
try {
const response = await fetch(`${API_BASE}/finances`);
const data = await response.json();
if (response.ok) {
resultDiv.innerHTML = `
<div class="success">
β
Finances API PASSED<br>
Found ${data.length} finance records<br>
First record: ${data[0]?.description || 'No records'}<br>
Type: ${data[0]?.type || 'N/A'}
</div>
`;
} else {
resultDiv.innerHTML = `<div class="error">β Finances API FAILED: ${response.status}</div>`;
}
} catch (error) {
resultDiv.innerHTML = `<div class="error">β Finances API ERROR: ${error.message}</div>`;
}
}
// Auto-test on page load
window.onload = function() {
console.log('π Testing Render API connection to:', API_BASE);
testHealth();
};
</script>
</body>
</html>