58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
const http = require('http');
|
|
|
|
const options = {
|
|
hostname: 'localhost',
|
|
port: 4001,
|
|
path: '/api/auth/login',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
},
|
|
};
|
|
|
|
const req = http.request(options, (res) => {
|
|
let data = '';
|
|
res.on('data', (chunk) => data += chunk);
|
|
res.on('end', () => {
|
|
if (!res.headers['set-cookie']) {
|
|
console.log('No cookie', data); return;
|
|
}
|
|
const cookie = res.headers['set-cookie'][0];
|
|
|
|
// Generate QR
|
|
const largeStr = 'a'.repeat(200000);
|
|
const postData = JSON.stringify({
|
|
name: 'Test QR',
|
|
type: 'dynamic',
|
|
dataType: 'URL',
|
|
destinationUrl: 'https://google.com',
|
|
designData: { image: 'data:image/png;base64,' + largeStr }
|
|
});
|
|
|
|
const options2 = {
|
|
hostname: 'localhost',
|
|
port: 4001,
|
|
path: '/api/qr/generate',
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Content-Length': Buffer.byteLength(postData),
|
|
'Cookie': cookie
|
|
}
|
|
};
|
|
|
|
const req2 = http.request(options2, (res2) => {
|
|
let d = '';
|
|
res2.on('data', c => d+=c);
|
|
res2.on('end', () => {
|
|
console.log('Status:', res2.statusCode);
|
|
console.log('Body:', d);
|
|
});
|
|
});
|
|
req2.write(postData);
|
|
req2.end();
|
|
});
|
|
});
|
|
req.write(JSON.stringify({email: 'admin@ckqr.com', password: 'password123'}));
|
|
req.end();
|