67 lines
2.0 KiB
JavaScript
67 lines
2.0 KiB
JavaScript
|
|
const axios = require('axios');
|
|||
|
|
|
|||
|
|
// 测试登录接口
|
|||
|
|
async function testLoginAPI() {
|
|||
|
|
console.log('🔍 测试政府端登录接口...\n');
|
|||
|
|
|
|||
|
|
const testCases = [
|
|||
|
|
{
|
|||
|
|
name: '本地后端直接测试',
|
|||
|
|
url: 'http://localhost:5352/api/auth/login',
|
|||
|
|
description: '直接访问后端服务'
|
|||
|
|
},
|
|||
|
|
{
|
|||
|
|
name: '生产环境nginx代理测试',
|
|||
|
|
url: 'https://ad.ningmuyun.com/api/government/auth/login',
|
|||
|
|
description: '通过nginx代理访问'
|
|||
|
|
}
|
|||
|
|
];
|
|||
|
|
|
|||
|
|
const testData = {
|
|||
|
|
username: 'admin',
|
|||
|
|
password: 'admin123'
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
for (const testCase of testCases) {
|
|||
|
|
console.log(`📋 ${testCase.name}`);
|
|||
|
|
console.log(` 描述: ${testCase.description}`);
|
|||
|
|
console.log(` URL: ${testCase.url}`);
|
|||
|
|
console.log(` 数据: ${JSON.stringify(testData)}`);
|
|||
|
|
|
|||
|
|
try {
|
|||
|
|
const response = await axios.post(testCase.url, testData, {
|
|||
|
|
headers: {
|
|||
|
|
'Content-Type': 'application/json'
|
|||
|
|
},
|
|||
|
|
timeout: 10000
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
console.log(` ✅ 状态码: ${response.status}`);
|
|||
|
|
console.log(` ✅ 响应: ${JSON.stringify(response.data, null, 2)}`);
|
|||
|
|
|
|||
|
|
} catch (error) {
|
|||
|
|
if (error.response) {
|
|||
|
|
console.log(` ❌ 状态码: ${error.response.status}`);
|
|||
|
|
console.log(` ❌ 错误信息: ${JSON.stringify(error.response.data, null, 2)}`);
|
|||
|
|
} else if (error.request) {
|
|||
|
|
console.log(` ❌ 网络错误: ${error.message}`);
|
|||
|
|
} else {
|
|||
|
|
console.log(` ❌ 请求配置错误: ${error.message}`);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log(' ' + '─'.repeat(50));
|
|||
|
|
console.log('');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
console.log('🎯 测试完成!');
|
|||
|
|
console.log('');
|
|||
|
|
console.log('📝 说明:');
|
|||
|
|
console.log(' - 如果本地测试成功但生产环境失败,说明nginx配置有问题');
|
|||
|
|
console.log(' - 如果两个都失败,说明后端服务有问题');
|
|||
|
|
console.log(' - 如果两个都成功,说明修复生效');
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// 运行测试
|
|||
|
|
testLoginAPI().catch(console.error);
|