-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-http.mjs
More file actions
69 lines (57 loc) · 1.74 KB
/
test-http.mjs
File metadata and controls
69 lines (57 loc) · 1.74 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
// Test HTTP server
import { spawn } from 'child_process';
console.log('Starting Etherscan MCP Server HTTP test...\n');
const server = spawn('node', ['dist/index.js'], {
env: {
...process.env,
ETHERSCAN_API_KEY: 'test_key_123',
PORT: '3000',
HOST: 'localhost'
}
});
server.stdout.on('data', (data) => {
console.log('Server:', data.toString().trim());
});
server.stderr.on('data', (data) => {
console.error('Server:', data.toString().trim());
});
server.on('error', (err) => {
console.error('Failed to start server:', err);
process.exit(1);
});
// Wait for server to start then test endpoints
setTimeout(async () => {
console.log('\n=== Testing HTTP endpoints ===\n');
try {
// Test health endpoint
console.log('1. Testing health endpoint...');
const healthRes = await fetch('http://localhost:3000/health');
const healthData = await healthRes.json();
console.log('✓ Health check response:', healthData);
console.log('\n2. Testing SSE endpoint connection...');
const sseRes = await fetch('http://localhost:3000/sse');
console.log('✓ SSE endpoint status:', sseRes.status, sseRes.statusText);
if (sseRes.ok) {
console.log('✓ SSE connection established');
}
console.log('\n✓ All HTTP tests passed!');
} catch (error) {
console.error('✗ Test failed:', error.message);
} finally {
console.log('\nShutting down server...');
server.kill();
setTimeout(() => process.exit(0), 500);
}
}, 2000);
// Cleanup on Ctrl+C
process.on('SIGINT', () => {
console.log('\nShutting down...');
server.kill();
process.exit();
});
// Auto-kill after 10 seconds
setTimeout(() => {
console.log('\nTimeout reached, shutting down...');
server.kill();
process.exit(0);
}, 10000);