Files
nxxmdata/government-backend/test-backend-service.js
2025-10-23 17:26:47 +08:00

63 lines
1.5 KiB
JavaScript

const axios = require('axios');
async function testBackendService() {
console.log('测试政府后端服务...');
const baseURL = 'http://localhost:5352';
const testAPIs = [
{
name: '健康检查',
url: '/health',
method: 'GET'
},
{
name: '根路径',
url: '/',
method: 'GET'
},
{
name: '养殖类型接口',
url: '/api/government/farm-types',
method: 'GET'
},
{
name: '养殖种类接口',
url: '/api/government/animal-types',
method: 'GET'
},
{
name: '数据览仓接口',
url: '/api/government/data-center',
method: 'GET'
}
];
for (const api of testAPIs) {
try {
console.log(`\n测试 ${api.name}...`);
console.log(`URL: ${baseURL}${api.url}`);
const response = await axios({
method: api.method,
url: `${baseURL}${api.url}`,
timeout: 5000
});
console.log(`✅ 状态码: ${response.status}`);
console.log(`✅ 响应: ${JSON.stringify(response.data).substring(0, 100)}...`);
} catch (error) {
console.log(`❌ 错误: ${error.message}`);
if (error.response) {
console.log(`❌ 状态码: ${error.response.status}`);
console.log(`❌ 响应: ${JSON.stringify(error.response.data)}`);
} else if (error.code === 'ECONNREFUSED') {
console.log(`❌ 连接被拒绝 - 服务可能没有启动`);
}
}
}
}
testBackendService().catch(console.error);