基础组件完善
This commit is contained in:
+158
@@ -0,0 +1,158 @@
|
||||
// 使用原生Node.js http模块发送请求
|
||||
import http from 'http';
|
||||
import { Buffer } from 'buffer';
|
||||
|
||||
// 测试GET请求 - 检查API服务器是否正常运行
|
||||
function testApiConnection() {
|
||||
console.log('测试API连接...');
|
||||
|
||||
// 设置请求选项
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': '1234567890'
|
||||
}
|
||||
};
|
||||
|
||||
// 创建请求
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log('响应头:', res.headers);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('响应数据:');
|
||||
try {
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log(JSON.stringify(parsedData, null, 2));
|
||||
} catch (e) {
|
||||
console.log('无法解析响应为JSON:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.error('请求错误:', error.message);
|
||||
if (error.code === 'ECONNREFUSED') {
|
||||
console.error('无法连接到API服务器 - 请确保服务器已启动并监听端口9000');
|
||||
}
|
||||
});
|
||||
|
||||
// 完成请求
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 测试POST请求 - 尝试创建一个测试评查点
|
||||
function testPostRequest() {
|
||||
console.log('\n测试POST请求...');
|
||||
|
||||
// 创建测试数据
|
||||
const testData = {
|
||||
code: 'TEST_CODE',
|
||||
name: '测试评查点',
|
||||
risk: 'low',
|
||||
is_enabled: false,
|
||||
is_draft: true,
|
||||
description: '这是一个测试评查点',
|
||||
references_laws: {
|
||||
name: '测试法规',
|
||||
articles: ['第一条'],
|
||||
content: '测试内容'
|
||||
},
|
||||
extraction_config: {
|
||||
llm: {
|
||||
fields: ['测试字段1', '测试字段2'],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '测试提示词'
|
||||
}
|
||||
},
|
||||
vlm: {
|
||||
fields: [
|
||||
{ name: '图片字段1', type: 'default' }
|
||||
],
|
||||
prompt_setting: {
|
||||
type: 'system',
|
||||
template: '测试图片提示词'
|
||||
}
|
||||
},
|
||||
regex: {
|
||||
fields: [
|
||||
{ field: '正则字段1', pattern: '\\d+' }
|
||||
]
|
||||
}
|
||||
},
|
||||
evaluation_config: {
|
||||
logicType: 'and',
|
||||
customLogic: '',
|
||||
rules: []
|
||||
}
|
||||
};
|
||||
|
||||
// 将数据转换为JSON字符串
|
||||
const postData = JSON.stringify(testData);
|
||||
|
||||
// 设置请求选项
|
||||
const options = {
|
||||
hostname: '127.0.0.1',
|
||||
port: 9000,
|
||||
path: '/admin/evaluation_points',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Accept': 'application/json',
|
||||
'Authorization': '1234567890',
|
||||
'Content-Length': Buffer.byteLength(postData)
|
||||
}
|
||||
};
|
||||
|
||||
// 创建请求
|
||||
const req = http.request(options, (res) => {
|
||||
console.log(`状态码: ${res.statusCode}`);
|
||||
console.log('响应头:', res.headers);
|
||||
|
||||
let data = '';
|
||||
|
||||
res.on('data', (chunk) => {
|
||||
data += chunk;
|
||||
});
|
||||
|
||||
res.on('end', () => {
|
||||
console.log('响应数据:');
|
||||
try {
|
||||
const parsedData = JSON.parse(data);
|
||||
console.log(JSON.stringify(parsedData, null, 2));
|
||||
} catch (e) {
|
||||
console.log('无法解析响应为JSON:', data);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
req.on('error', (error) => {
|
||||
console.error('请求错误:', error.message);
|
||||
});
|
||||
|
||||
// 发送数据
|
||||
req.write(postData);
|
||||
|
||||
// 完成请求
|
||||
req.end();
|
||||
}
|
||||
|
||||
// 执行测试
|
||||
testApiConnection();
|
||||
|
||||
// 等待3秒后执行POST测试
|
||||
setTimeout(() => {
|
||||
testPostRequest();
|
||||
}, 3000);
|
||||
Reference in New Issue
Block a user