| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- // API配置测试脚本
- import http from 'http';
- console.log('🧪 测试API配置功能...\n');
- async function testApiConnection() {
- console.log('1. 测试后端API连接...');
- return new Promise((resolve, reject) => {
- const req = http.request({
- hostname: 'localhost',
- port: 8000,
- path: '/api/announcement?page=1&page_size=10',
- method: 'GET',
- headers: {
- 'Content-Type': 'application/json'
- }
- }, (res) => {
- let data = '';
- console.log(`状态码: ${res.statusCode}`);
- res.on('data', (chunk) => {
- data += chunk;
- });
- res.on('end', () => {
- try {
- const response = JSON.parse(data);
- console.log('API响应:', JSON.stringify(response, null, 2));
- resolve(response);
- } catch (e) {
- console.error('解析响应失败:', e);
- reject(e);
- }
- });
- });
- req.on('error', (e) => {
- console.error('请求失败:', e);
- reject(e);
- });
- req.end();
- });
- }
- // 运行测试
- testApiConnection()
- .then(() => {
- console.log('\n✅ API连接测试成功!');
- })
- .catch((error) => {
- console.error('\n❌ API连接测试失败:', error.message);
- });
|