Spaces:
Paused
Paused
File size: 780 Bytes
8395368 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import axios from 'axios';
import fs from 'fs';
async function testApi() {
try {
console.log('Fetching http://localhost:5001/api/products...');
const response = await axios.get('http://localhost:5001/api/products');
console.log('Success:', response.status);
fs.writeFileSync('server/api_success.json', JSON.stringify(response.data, null, 2));
} catch (error) {
console.log('Error:', error.message);
if (error.response) {
console.log('Status:', error.response.status);
console.log('Data:', JSON.stringify(error.response.data, null, 2));
fs.writeFileSync('server/api_error.json', JSON.stringify(error.response.data, null, 2));
} else {
fs.writeFileSync('server/api_network_error.txt', error.message);
}
}
}
testApi();
|