-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
38 lines (32 loc) · 1.31 KB
/
debug.js
File metadata and controls
38 lines (32 loc) · 1.31 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
// Debug script to test frontend logic
async function testAPIResponse() {
try {
const response = await fetch('http://localhost:3001/api/query', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ message: 'I need a router for gaming' })
});
const result = await response.json();
console.log('Full response:', JSON.stringify(result, null, 2));
console.log('Success:', result.success);
console.log('Has data:', !!result.data);
if (result.success) {
console.log('Intent:', result.data.intent);
console.log('Result type:', typeof result.data.result);
console.log('Result length:', Array.isArray(result.data.result) ? result.data.result.length : 'Not array');
}
// Test the frontend logic
if (!result.success) {
console.log('Would show error:', result.error || 'Something went wrong');
} else {
console.log('Would pass to displayResponse:', result.data);
}
} catch (error) {
console.error('Network error:', error.message);
}
}
// Import fetch if not available
if (typeof fetch === 'undefined') {
global.fetch = require('node-fetch');
}
testAPIResponse();