Files
nxxmdata/government-backend/diagnose-url-issue.js

76 lines
2.5 KiB
JavaScript
Raw Normal View History

2025-10-17 17:29:11 +08:00
const axios = require('axios');
// 诊断URL重复问题
async function diagnoseURLIssue() {
console.log('🔍 诊断政府端API URL重复问题...\n');
const testURLs = [
{
name: '正确的部门接口URL',
url: 'https://ad.ningmuyun.com/api/government/departments',
description: '应该是正确的API路径'
},
{
name: '错误的重复URL',
url: 'https://ad.ningmuyun.com/api/government/government/departments',
description: '您提到的重复路径问题'
},
{
name: '静态文件路径测试',
url: 'https://ad.ningmuyun.com/government/',
description: '测试静态文件路径是否正常'
}
];
for (const test of testURLs) {
console.log(`📋 ${test.name}`);
console.log(` URL: ${test.url}`);
console.log(` 说明: ${test.description}`);
try {
const response = await axios.get(test.url, {
timeout: 10000,
validateStatus: function (status) {
return status < 500; // 接受所有小于500的状态码
}
});
console.log(` ✅ 状态码: ${response.status}`);
console.log(` ✅ 响应类型: ${response.headers['content-type']}`);
if (response.status === 200) {
if (response.headers['content-type']?.includes('application/json')) {
console.log(` ✅ 返回JSON数据: ${JSON.stringify(response.data).substring(0, 100)}...`);
} else {
console.log(` ✅ 返回HTML内容 (可能是静态文件)`);
}
} else if (response.status === 404) {
console.log(` ❌ 404错误: 路径不存在`);
} else if (response.status === 401) {
console.log(` ✅ 401错误: 需要认证 (API接口正常)`);
}
} catch (error) {
if (error.response) {
console.log(` ❌ 状态码: ${error.response.status}`);
console.log(` ❌ 错误: ${error.response.statusText}`);
} else {
console.log(` ❌ 网络错误: ${error.message}`);
}
}
console.log(' ' + '─'.repeat(60));
console.log('');
}
console.log('🎯 诊断完成!');
console.log('');
console.log('📝 分析结果:');
console.log(' - 如果正确的URL返回404说明nginx配置有问题');
console.log(' - 如果错误的URL也能访问说明有路径重写问题');
console.log(' - 如果静态文件路径正常说明nginx基本配置正确');
}
// 运行诊断
diagnoseURLIssue().catch(console.error);