-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.js
More file actions
93 lines (81 loc) · 3.34 KB
/
Copy pathtest-server.js
File metadata and controls
93 lines (81 loc) · 3.34 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
/**
* Simple test script to verify Express server is working
*/
const http = require('http');
const PORT = 8080;
const BASE_URL = `http://localhost:${PORT}`;
function testEndpoint(path, description) {
return new Promise((resolve, reject) => {
const url = `${BASE_URL}${path}`;
console.log(`\nTesting: ${description}`);
console.log(` URL: ${url}`);
http.get(url, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
console.log(` Status: ${res.statusCode}`);
console.log(` Content-Type: ${res.headers['content-type']}`);
console.log(` Content-Length: ${res.headers['content-length']} bytes`);
console.log(` CORS: ${res.headers['access-control-allow-origin'] || 'Not set'}`);
if (res.statusCode === 200) {
if (path === '/') {
console.log(` ✓ Root route working - HTML content received (${data.length} bytes)`);
console.log(` First 100 chars: ${data.substring(0, 100)}...`);
} else if (path.includes('.json')) {
console.log(` ✓ JSON endpoint working`);
try {
const json = JSON.parse(data);
console.log(` Response: ${JSON.stringify(json).substring(0, 100)}...`);
} catch (e) {
console.log(` Response: ${data.substring(0, 100)}...`);
}
} else if (path.includes('.png')) {
console.log(` ✓ Image endpoint working - received ${data.length} bytes`);
} else if (path.includes('.css')) {
console.log(` ✓ CSS endpoint working - received ${data.length} bytes`);
console.log(` First 100 chars: ${data.substring(0, 100)}...`);
}
resolve(true);
} else {
console.log(` ✗ Failed with status ${res.statusCode}`);
reject(new Error(`Status ${res.statusCode}`));
}
});
}).on('error', (err) => {
console.log(` ✗ Error: ${err.message}`);
reject(err);
});
});
}
async function runTests() {
console.log('='.repeat(60));
console.log('DIG Network Server Test Script');
console.log('='.repeat(60));
console.log(`Testing server at: ${BASE_URL}`);
console.log('Make sure the server is running: npm run server');
try {
await testEndpoint('/', 'Root route (test.html)');
await testEndpoint('/test/data.json', 'JSON endpoint');
await testEndpoint('/test/image1.png', 'Image endpoint');
await testEndpoint('/test/styles.css', 'CSS endpoint');
await testEndpoint('/test/script.js', 'JavaScript endpoint');
console.log('\n' + '='.repeat(60));
console.log('✓ All tests passed! Server is working correctly.');
console.log('='.repeat(60));
console.log('\nIf the browser still shows issues, check:');
console.log(' 1. Browser console for errors');
console.log(' 2. Network tab to see if requests are being made');
console.log(' 3. Extension is installed and enabled');
console.log(' 4. CORS headers are present (they are!)');
} catch (error) {
console.log('\n' + '='.repeat(60));
console.log('✗ Test failed:', error.message);
console.log('='.repeat(60));
console.log('\nMake sure the server is running:');
console.log(' cd server && npm start');
process.exit(1);
}
}
runTests();