You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

63 lines
2.0 KiB

/**
* 服务状态检查脚本
* 检查前后端服务是否正常运行
*/
const http = require('http');
const CONFIG = {
backend: { host: 'localhost', port: 8888, path: '/api/v1/users' },
frontend: { host: 'localhost', port: 5175, path: '/' },
};
function checkService(name, config) {
return new Promise((resolve) => {
const req = http.get(
{ hostname: config.host, port: config.port, path: config.path, timeout: 2000 },
(res) => {
const status = res.statusCode === 200 || res.statusCode === 401; // 401 表示需要认证,服务正常
console.log(`${status ? '✅' : '⚠️ '} ${name}: http://${config.host}:${config.port}${config.path} (${res.statusCode})`);
resolve({ name, status: true, statusCode: res.statusCode });
}
);
req.on('error', (err) => {
console.log(`${name}: http://${config.host}:${config.port}${config.path} - ${err.message}`);
resolve({ name, status: false, error: err.message });
});
req.on('timeout', () => {
req.destroy();
console.log(`⏱️ ${name}: 连接超时`);
resolve({ name, status: false, error: 'timeout' });
});
});
}
async function main() {
console.log('🔍 检查服务状态...\n');
const results = await Promise.all([
checkService('后端服务', CONFIG.backend),
checkService('前端服务', CONFIG.frontend),
]);
console.log('');
const allReady = results.every(r => r.status);
if (allReady) {
console.log('✅ 所有服务正常运行,可以执行测试');
console.log('\n📋 测试执行命令:');
console.log(' npm run test:e2e - 启动测试环境');
console.log(' 或询问 Claude: "执行全部 Playwright 测试"');
} else {
console.log('⚠️ 部分服务未启动');
console.log('\n请运行以下命令启动服务:');
console.log(' 后端: cd backend && go run base.go -f etc/base-api.yaml');
console.log(' 前端: cd frontend/react-shadcn/pc && npm run dev');
}
process.exit(allReady ? 0 : 1);
}
main();