85 lines
2.9 KiB
JavaScript
85 lines
2.9 KiB
JavaScript
const axios = require('axios');
|
||
|
||
// 测试路径修复效果
|
||
async function testPathFix() {
|
||
console.log('🔍 测试政府端API路径修复效果...\n');
|
||
|
||
const testCases = [
|
||
{
|
||
name: '岗位列表接口测试',
|
||
url: 'https://ad.ningmuyun.com/api/government/positions',
|
||
expected: '应该返回岗位列表数据'
|
||
},
|
||
{
|
||
name: '部门列表接口测试',
|
||
url: 'https://ad.ningmuyun.com/api/government/departments',
|
||
expected: '应该返回部门列表数据'
|
||
},
|
||
{
|
||
name: '养殖户列表接口测试',
|
||
url: 'https://ad.ningmuyun.com/api/government/farmers',
|
||
expected: '应该返回养殖户列表数据'
|
||
},
|
||
{
|
||
name: '市场价格接口测试',
|
||
url: 'https://ad.ningmuyun.com/api/government/market-price?type=beef',
|
||
expected: '应该返回市场价格数据'
|
||
}
|
||
];
|
||
|
||
for (const test of testCases) {
|
||
console.log(`📋 ${test.name}`);
|
||
console.log(` URL: ${test.url}`);
|
||
console.log(` 预期: ${test.expected}`);
|
||
|
||
try {
|
||
const response = await axios.get(test.url, {
|
||
timeout: 10000,
|
||
validateStatus: function (status) {
|
||
return status < 500; // 接受所有小于500的状态码
|
||
}
|
||
});
|
||
|
||
console.log(` ✅ 状态码: ${response.status}`);
|
||
|
||
if (response.status === 200) {
|
||
console.log(` ✅ 成功: 返回了正确的数据`);
|
||
if (Array.isArray(response.data)) {
|
||
console.log(` 📊 数据量: ${response.data.length} 条记录`);
|
||
} else if (response.data && typeof response.data === 'object') {
|
||
console.log(` 📊 数据类型: 对象,包含 ${Object.keys(response.data).length} 个字段`);
|
||
}
|
||
} else if (response.status === 401) {
|
||
console.log(` ✅ 正常: 需要认证 (接口路径正确)`);
|
||
} else if (response.status === 404) {
|
||
console.log(` ❌ 错误: 路径不存在`);
|
||
}
|
||
|
||
} catch (error) {
|
||
if (error.response) {
|
||
console.log(` ❌ 状态码: ${error.response.status}`);
|
||
console.log(` ❌ 错误: ${error.response.statusText}`);
|
||
|
||
if (error.response.status === 404) {
|
||
console.log(` 🔍 分析: 可能是nginx配置问题,路径映射不正确`);
|
||
}
|
||
} else {
|
||
console.log(` ❌ 网络错误: ${error.message}`);
|
||
}
|
||
}
|
||
|
||
console.log(' ' + '─'.repeat(60));
|
||
console.log('');
|
||
}
|
||
|
||
console.log('🎯 测试完成!');
|
||
console.log('');
|
||
console.log('📝 修复说明:');
|
||
console.log(' - 修复前: proxy_pass http://localhost:5352/api/government/; (会重复路径)');
|
||
console.log(' - 修复后: proxy_pass http://localhost:5352/; (正确映射)');
|
||
console.log(' - 现在 /api/government/positions 应该正确映射到 /api/government/positions');
|
||
}
|
||
|
||
// 运行测试
|
||
testPathFix().catch(console.error);
|