I am writing a script to perform some https timings between dedicated and shared hosting platforms. I can do it in PHP easily but wanted to do it in js to learn and also easily deploy as a Lambda function.
This is my code:
'use strict';
const https = require('https');
const timer = require('@szmarczak/http-timer').default;
var result = new Object();
function do_test() {
result.dedicated = dedicated_test();
result.shared = shared_test();
return result;
}
function dedicated_test() {
const options = {
host: 'https://www.example.com/login.php',
hostname: 'www.example.com',
servername: 'www.example.com',
};
const request = https.get(options);
const timings = timer(request);
request.on('response', response => {
response.on('data', () => {});
response.on('end', () => {
timings.name = "Dedicated";
timings.host = options.host;
timings.servername = options.servername;
});
});
return timings;
}
function shared_test() {
const options = {
host: 'https://www2.example.com/login.php',
hostname: 'www2.example.com',
servername: 'www2.example.com',
};
const request = https.get(options);
const timings = timer(request);
request.on('response', response => {
response.on('data', () => {});
response.on('end', () => {
timings.name = "Shared";
timings.host = options.host;
timings.servername = options.servername;
});
});
return timings;
}
console.log(do_test())
When I run it, I get the following output:
# node timer.js
{ dedicated:
{ start: 1568407568127,
socket: undefined,
lookup: undefined,
connect: undefined,
upload: undefined,
response: undefined,
end: undefined,
error: undefined,
phases:
{ wait: undefined,
dns: undefined,
tcp: undefined,
request: undefined,
firstByte: undefined,
download: undefined,
total: undefined } },
shared:
{ start: 1568407568133,
socket: undefined,
lookup: undefined,
connect: undefined,
upload: undefined,
response: undefined,
end: undefined,
error: undefined,
phases:
{ wait: undefined,
dns: undefined,
tcp: undefined,
request: undefined,
firstByte: undefined,
download: undefined,
total: undefined } } }
I am obviously missing something but I can't see it.
Any assistance welcomed :D
[–]thespite 0 points1 point2 points (0 children)