59 lines
2.3 KiB
JavaScript
59 lines
2.3 KiB
JavaScript
import { Client } from 'ssh2';
|
|
|
|
const conn = new Client();
|
|
|
|
conn.on('ready', () => {
|
|
console.log('=== 在服务器上测试API ===\n');
|
|
|
|
console.log('1. 测试查询所有订单:');
|
|
conn.exec('curl -s http://localhost:4000/api/orders | head -50', (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
let output = '';
|
|
stream.on('data', (d) => output += d.toString());
|
|
stream.on('close', () => {
|
|
console.log('输出:', output);
|
|
|
|
console.log('\n2. 测试查询宁赜的订单:');
|
|
conn.exec('curl -s "http://localhost:4000/api/orders?collector=宁赜"', (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
let output2 = '';
|
|
stream.on('data', (d) => output2 += d.toString());
|
|
stream.on('close', () => {
|
|
console.log('输出:', output2);
|
|
|
|
console.log('\n3. 测试创建订单:');
|
|
conn.exec('curl -s -X POST http://localhost:4000/api/orders -H "Content-Type: application/json" -d \'{"items":[{"category":"001","name":"纸类(书本)","weight":5,"unit":"kg","price":1.2,"amount":6}],"totalWeight":5,"totalPrice":6,"city":"天津市","district":"高新区","community":"测试社区","user":"测试用户","collector":"宁赜"}\'', (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
let output3 = '';
|
|
stream.on('data', (d) => output3 += d.toString());
|
|
stream.on('close', () => {
|
|
console.log('输出:', output3);
|
|
|
|
console.log('\n4. 再次查询宁赜的订单:');
|
|
conn.exec('curl -s "http://localhost:4000/api/orders?collector=宁赜"', (err, stream) => {
|
|
if (err) { console.log('ERR:', err); conn.end(); return; }
|
|
let output4 = '';
|
|
stream.on('data', (d) => output4 += d.toString());
|
|
stream.on('close', () => {
|
|
console.log('输出:', output4);
|
|
conn.end();
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
conn.on('error', (err) => {
|
|
console.log('连接错误:', err.message);
|
|
});
|
|
|
|
conn.connect({
|
|
host: 'hs.yifenbao.cn',
|
|
port: 22,
|
|
username: 'root',
|
|
password: 'Torch1112'
|
|
}); |