-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhealth-check.js
More file actions
executable file
·95 lines (79 loc) · 2.82 KB
/
health-check.js
File metadata and controls
executable file
·95 lines (79 loc) · 2.82 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
#!/usr/bin/env node
/**
* Simple health check script for the personal website
* Tests connectivity to Supabase services
*/
const http = require('http');
// Colors for terminal output
const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
reset: '\x1b[0m'
};
function log(level, message) {
const timestamp = new Date().toISOString();
const colorMap = {
'INFO': colors.blue,
'SUCCESS': colors.green,
'WARNING': colors.yellow,
'ERROR': colors.red
};
console.log(`${colorMap[level]}[${level}]${colors.reset} ${timestamp} - ${message}`);
}
function checkEndpoint(url, name) {
return new Promise((resolve) => {
const req = http.get(url, (res) => {
if (res.statusCode >= 200 && res.statusCode < 300) {
log('SUCCESS', `${name} is accessible (${res.statusCode})`);
resolve(true);
} else {
log('WARNING', `${name} returned status ${res.statusCode}`);
resolve(false);
}
});
req.on('error', (err) => {
log('ERROR', `${name} is not accessible: ${err.message}`);
resolve(false);
});
req.setTimeout(5000, () => {
req.destroy();
log('ERROR', `${name} request timed out`);
resolve(false);
});
});
}
async function runHealthCheck() {
log('INFO', 'Starting health check...');
const endpoints = [
{ url: 'http://localhost:5173', name: 'Frontend' },
{ url: 'http://localhost:3000', name: 'Supabase Studio' },
{ url: 'http://localhost:8000/health', name: 'Supabase API Health' },
{ url: 'http://localhost:8000/rest/v1/', name: 'Supabase REST API' },
];
let successCount = 0;
for (const endpoint of endpoints) {
const isHealthy = await checkEndpoint(endpoint.url, endpoint.name);
if (isHealthy) successCount++;
// Add a small delay between checks
await new Promise(resolve => setTimeout(resolve, 100));
}
log('INFO', `Health check complete: ${successCount}/${endpoints.length} services accessible`);
if (successCount === endpoints.length) {
log('SUCCESS', 'All services are running correctly!');
log('INFO', 'You can access:');
log('INFO', ' - Frontend: http://localhost:5173');
log('INFO', ' - Supabase Studio: http://localhost:3000');
log('INFO', ' - Supabase API: http://localhost:8000');
process.exit(0);
} else {
log('WARNING', 'Some services are not accessible. Check the logs with: docker compose logs');
process.exit(1);
}
}
// Run the health check
runHealthCheck().catch((err) => {
log('ERROR', `Health check failed: ${err.message}`);
process.exit(1);
});