const axios = require('axios'); async function testRoutes() { console.log('测试不同的路由...\n'); // 测试几个路由 const routes = [ { method: 'GET', path: '/' }, { method: 'POST', path: '/login' }, { method: 'POST', path: '/admin/info' }, { method: 'GET', path: '/admin/info' }, ]; for (const route of routes) { try { console.log(`测试 ${route.method} ${route.path}`); const config = { method: route.method, url: `http://localhost:3000${route.path}`, headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }; const res = await axios(config); console.log(` 状态: ${res.status}`); console.log(` Content-Type: ${res.headers['content-type']}`); if (typeof res.data === 'string' && res.data.includes('404')) { console.log(` 响应: 404页面`); } else { console.log(` 响应:`, JSON.stringify(res.data).substring(0, 100)); } } catch (error) { if (error.response) { console.log(` 错误: 状态码 ${error.response.status}`); } else { console.log(` 错误: ${error.message}`); } } console.log(''); } } testRoutes();