-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-env.js
More file actions
101 lines (82 loc) · 2.93 KB
/
Copy pathvalidate-env.js
File metadata and controls
101 lines (82 loc) · 2.93 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
#!/usr/bin/env node
/**
* Environment Validation Script
*
* This script validates that the local development environment is properly
* configured and accessible at localhost:3000
*/
const http = require('http');
const LOCALHOST_URL = 'http://localhost:3000';
const TIMEOUT = 5000;
// ANSI color codes
const colors = {
reset: '\x1b[0m',
green: '\x1b[32m',
red: '\x1b[31m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
};
function log(message, color = 'reset') {
console.log(`${colors[color]}${message}${colors.reset}`);
}
function checkUrl(url, description) {
return new Promise((resolve) => {
const req = http.get(url, { timeout: TIMEOUT }, (res) => {
// Consume response body to free up memory and properly close connection
res.resume();
const success = res.statusCode >= 200 && res.statusCode < 400;
if (success) {
log(`✓ ${description}: ${res.statusCode}`, 'green');
} else {
log(`✗ ${description}: ${res.statusCode}`, 'red');
}
resolve({ url, success, statusCode: res.statusCode });
});
req.on('error', (err) => {
log(`✗ ${description}: ${err.message}`, 'red');
resolve({ url, success: false, error: err.message });
});
req.on('timeout', () => {
req.destroy();
log(`✗ ${description}: Timeout`, 'yellow');
resolve({ url, success: false, error: 'Timeout' });
});
});
}
async function validateEnvironment() {
log('\n🔍 Validating Local Development Environment\n', 'blue');
const checks = [
{ url: `${LOCALHOST_URL}`, description: 'Homepage' },
{ url: `${LOCALHOST_URL}/tech-radar`, description: 'Tech Radar Page' },
{ url: `${LOCALHOST_URL}/tech-radar/docs`, description: 'Docs Page' },
{ url: `${LOCALHOST_URL}/tech-radar/pricing`, description: 'Pricing Page' },
{ url: `${LOCALHOST_URL}/mcpflare`, description: 'MCPflare Page' },
{ url: `${LOCALHOST_URL}/legal/privacy`, description: 'Privacy Page' },
{ url: `${LOCALHOST_URL}/legal/terms`, description: 'Terms Page' },
{ url: `${LOCALHOST_URL}/legal/security`, description: 'Security Page' },
];
const results = [];
for (const check of checks) {
const result = await checkUrl(check.url, check.description);
results.push(result);
}
const allPassed = results.every(r => r.success);
log('', 'reset');
if (allPassed) {
log('✓ All environment checks passed!', 'green');
log('The development environment is ready.', 'green');
process.exit(0);
} else {
log('✗ Some checks failed!', 'red');
log('Make sure the dev server is running: npm run dev', 'yellow');
process.exit(1);
}
}
// Run validation
if (require.main === module) {
validateEnvironment().catch((err) => {
log(`\n✗ Validation failed: ${err.message}`, 'red');
process.exit(1);
});
}
module.exports = { validateEnvironment, checkUrl };