-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdebug_fragments.cjs
More file actions
37 lines (31 loc) · 841 Bytes
/
Copy pathdebug_fragments.cjs
File metadata and controls
37 lines (31 loc) · 841 Bytes
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
const http = require('http');
const options = {
hostname: 'localhost',
port: 3001,
path: '/api/knowledge/fragments',
method: 'GET',
};
const req = http.request(options, (res) => {
console.log(`STATUS: ${res.statusCode}`);
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
console.log('Raw Data Length:', data.length);
const json = JSON.parse(data);
console.log('Success:', json.success);
console.log('Fragment Count:', json.fragments ? json.fragments.length : 'undefined');
if (json.error) {
console.log('Error:', json.error);
}
} catch (e) {
console.log('Response not JSON:', data.substring(0, 200));
}
});
});
req.on('error', (e) => {
console.error(`problem with request: ${e.message}`);
});
req.end();