test-spiderfoot-api.js•1.65 kB
// Simple test script to verify SpiderFoot API connection
import axios from 'axios';
async function testSpiderFootAPI() {
const baseUrl = 'http://localhost:5001';
try {
console.log(`Testing connection to SpiderFoot at ${baseUrl}`);
// Test ping endpoint
console.log('\n1. Testing ping endpoint...');
const pingResponse = await axios.get(`${baseUrl}/ping`);
console.log('Ping response:', pingResponse.data);
// Test modules endpoint
console.log('\n2. Testing modules endpoint...');
const modulesResponse = await axios.get(`${baseUrl}/modules`);
console.log(`Found ${Object.keys(modulesResponse.data).length} modules`);
console.log('\n✅ SpiderFoot API is accessible and responding correctly');
} catch (error) {
console.error('\n❌ Error testing SpiderFoot API:');
if (error.response) {
// The request was made and the server responded with a status code
// that falls out of the range of 2xx
console.error('Status:', error.response.status);
console.error('Data:', error.response.data);
console.error('Headers:', error.response.headers);
} else if (error.request) {
// The request was made but no response was received
console.error('No response received. Is SpiderFoot running?');
console.error('Request:', error.request);
} else {
// Something happened in setting up the request that triggered an Error
console.error('Error:', error.message);
}
console.error('\n💡 Make sure SpiderFoot is running and accessible at', baseUrl);
process.exit(1);
}
}
// Run the test
testSpiderFootAPI();