-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_backend_connection.js
More file actions
executable file
·53 lines (43 loc) · 1.29 KB
/
test_backend_connection.js
File metadata and controls
executable file
·53 lines (43 loc) · 1.29 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
// Simple backend connection test
// Run with: node test_backend_connection.js
const http = require('http');
console.log('🧪 Testing backend connection...');
// Test the health endpoint
const req = http.get('http://localhost:8000/api/health', (res) => {
console.log(`🔍 Status Code: ${res.statusCode}`);
if (res.statusCode !== 200) {
console.error('❌ Backend connection failed!');
process.exit(1);
}
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const response = JSON.parse(data);
console.log('📊 Response:', response);
if (response.status === 'healthy') {
console.log('✅ Backend connection successful!');
process.exit(0);
} else {
console.error('❌ Backend is not healthy!');
process.exit(1);
}
} catch (error) {
console.error('❌ Failed to parse response:', error.message);
process.exit(1);
}
});
});
req.on('error', (error) => {
console.error('❌ Connection error:', error.message);
console.error('Make sure the backend server is running on http://localhost:8000');
process.exit(1);
});
// Set timeout
req.setTimeout(5000, () => {
console.error('❌ Connection timeout!');
req.destroy();
process.exit(1);
});