-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api-directly.js
More file actions
83 lines (69 loc) · 2.43 KB
/
test-api-directly.js
File metadata and controls
83 lines (69 loc) · 2.43 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
/**
* Direct API Test Script
* Run this in the browser console to test API connectivity
*/
console.log('🔧 Testing API connectivity...');
const API_BASE_URL = 'https://vtqjfznspc.execute-api.ap-south-1.amazonaws.com/dev';
const token = localStorage.getItem('aquachain_token') || localStorage.getItem('authToken');
console.log('🔑 Token status:', token ? 'Present' : 'Missing');
if (token) {
console.log('🔑 Token type:', token.startsWith('dev-token-') ? 'Development' : 'Production');
console.log('🔑 Token preview:', token.substring(0, 20) + '...');
}
// Test the devices endpoint
async function testDevicesAPI() {
try {
console.log('📡 Testing /api/devices endpoint...');
const response = await fetch(`${API_BASE_URL}/api/devices`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': token ? `Bearer ${token}` : '',
},
});
console.log('📊 Response status:', response.status);
console.log('📊 Response headers:', Object.fromEntries(response.headers.entries()));
if (!response.ok) {
console.error('❌ Request failed');
// Try to get response body
const contentType = response.headers.get('content-type');
if (contentType && contentType.includes('application/json')) {
const errorData = await response.json();
console.error('❌ Error data:', errorData);
} else {
const errorText = await response.text();
console.error('❌ Error text:', errorText);
}
} else {
const data = await response.json();
console.log('✅ Success! Response data:', data);
}
} catch (error) {
console.error('❌ Network error:', error);
}
}
// Test the health endpoint
async function testHealthAPI() {
try {
console.log('📡 Testing /api/health endpoint...');
const response = await fetch(`${API_BASE_URL}/api/health`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
});
console.log('📊 Health response status:', response.status);
if (response.ok) {
const data = await response.json();
console.log('✅ Health check passed:', data);
} else {
console.error('❌ Health check failed');
}
} catch (error) {
console.error('❌ Health check network error:', error);
}
}
// Run tests
testHealthAPI();
testDevicesAPI();
console.log('🔧 Test completed. Check the results above.');