2026-03-26 16:52:54 +07:00
|
|
|
const { request } = require('undici');
|
2026-04-07 11:30:11 +07:00
|
|
|
const config = require('../config/config');
|
2026-03-26 16:52:54 +07:00
|
|
|
|
|
|
|
|
async function deliver(payload) {
|
|
|
|
|
const body = JSON.stringify(payload);
|
|
|
|
|
const start = Date.now();
|
|
|
|
|
const headers = {
|
|
|
|
|
'content-type': 'application/json'
|
|
|
|
|
};
|
2026-04-09 16:34:53 +07:00
|
|
|
|
2026-03-26 16:52:54 +07:00
|
|
|
if (config.clqms.token) {
|
|
|
|
|
headers.authorization = `Bearer ${config.clqms.token}`;
|
|
|
|
|
}
|
2026-04-09 16:34:53 +07:00
|
|
|
|
2026-03-26 16:52:54 +07:00
|
|
|
const response = await request(config.clqms.url, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers,
|
|
|
|
|
body,
|
|
|
|
|
keepaliveTimeout: 0,
|
|
|
|
|
bodyTimeout: config.clqms.timeout
|
|
|
|
|
});
|
2026-04-09 16:34:53 +07:00
|
|
|
|
2026-03-26 16:52:54 +07:00
|
|
|
const latency = Date.now() - start;
|
|
|
|
|
const responseBody = await response.body.text();
|
|
|
|
|
return {
|
|
|
|
|
code: response.statusCode,
|
|
|
|
|
body: responseBody,
|
|
|
|
|
latency
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { deliver };
|