-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest-https.js
More file actions
43 lines (34 loc) · 1.22 KB
/
test-https.js
File metadata and controls
43 lines (34 loc) · 1.22 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
#!/usr/bin/env node
// Test HTTPS certificate ignoring functionality
console.log('Testing HTTPS certificate ignoring...');
async function testHttpsConnection() {
const url = 'https://localhost:5114/api/status';
// Save original setting
const originalSetting = process.env.NODE_TLS_REJECT_UNAUTHORIZED;
try {
console.log(`Attempting to connect to: ${url}`);
// Set to ignore certificates
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
console.log('Set NODE_TLS_REJECT_UNAUTHORIZED=0');
const response = await fetch(url);
console.log(`Response status: ${response.status}`);
if (response.ok) {
const data = await response.json();
console.log('Response data:', data);
console.log('✅ HTTPS certificate ignoring works!');
} else {
console.log('❌ Got non-OK response');
}
} catch (error) {
console.error('❌ Connection failed:', error.message);
} finally {
// Restore original setting
if (originalSetting !== undefined) {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = originalSetting;
} else {
delete process.env.NODE_TLS_REJECT_UNAUTHORIZED;
}
console.log('Restored original TLS setting');
}
}
testHttpsConnection();