46 lines
1.3 KiB
JavaScript
46 lines
1.3 KiB
JavaScript
const http = require('http');
|
|
const https = require('https');
|
|
const zlib = require('zlib');
|
|
|
|
async function sendRequest(path, data) {
|
|
const payload = JSON.stringify(data);
|
|
|
|
const options = {
|
|
hostname: '127.0.0.1',
|
|
port: 6969,
|
|
path: path,
|
|
method: 'POST',
|
|
rejectUnauthorized: false,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Content-Length': Buffer.byteLength(payload),
|
|
'Accept-Encoding': 'identity',
|
|
'requestcompressed': '0',
|
|
'responsecompressed': '0'
|
|
}
|
|
};
|
|
|
|
return new Promise((resolve, reject) => {
|
|
const req = https.request(options, (res) => {
|
|
let result = '';
|
|
res.on('data', d => result += d);
|
|
res.on('end', () => resolve({ status: res.statusCode, body: result }));
|
|
});
|
|
req.on('error', reject);
|
|
req.write(payload); // We pass uncompressed for now using requestcompressed: 0
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
async function run() {
|
|
console.log("Registering...");
|
|
const regRes = await sendRequest('/launcher/profile/register', { username: 'testuser3', password: 'testpassword3', edition: 'Standard' });
|
|
console.log(regRes);
|
|
|
|
console.log("Logging in...");
|
|
const loginRes = await sendRequest('/launcher/profile/login', { username: 'testuser3', password: 'testpassword3' });
|
|
console.log(loginRes);
|
|
}
|
|
|
|
run();
|