35 lines
889 B
JavaScript
35 lines
889 B
JavaScript
const http = require('http');
|
|
const token = process.argv[2];
|
|
const method = process.argv[3]; // e.g. store.list
|
|
const reqBody = process.argv[4] || '{}';
|
|
|
|
const options = {
|
|
hostname: 'localhost',
|
|
port: 6060,
|
|
path: `/system?method=${method}&v=1×tamp=${Math.floor(Date.now() / 1000)}`,
|
|
method: 'POST',
|
|
headers: {
|
|
platform: 'web',
|
|
project: 'wms',
|
|
Authorization: `Bearer ${token}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
};
|
|
|
|
const req = http.request(options, res => {
|
|
let data = '';
|
|
res.on('data', chunk => data += chunk);
|
|
res.on('end', () => {
|
|
console.log(`STATUS: ${res.statusCode}`);
|
|
try {
|
|
const json = JSON.parse(data);
|
|
console.log(JSON.stringify(json, null, 2));
|
|
} catch (e) {
|
|
console.log(data.substring(0, 1000));
|
|
}
|
|
});
|
|
});
|
|
req.on('error', e => console.error('ERROR:', e.message));
|
|
req.write(reqBody);
|
|
req.end();
|