Skip to content

Commit

Permalink
feat(api): add log output for speedtest runner
Browse files Browse the repository at this point in the history
  • Loading branch information
MauriceNino committed Jun 11, 2022
1 parent 5d7462c commit 26267b2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,11 @@ server.listen(CONFIG.port, async () => {

try {
console.log('Running speed-test (this may take a few minutes)...');
await runSpeedTest();
console.log('Speed-test completed successfully');
const usedRunner = await runSpeedTest();
console.log(
`Speed-test completed successfully [${usedRunner}]`,
getStaticServerInfo().network
);
} catch (e) {
console.warn(e);
}
Expand Down
6 changes: 5 additions & 1 deletion apps/api/src/static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ const commandExists = async (command: string): Promise<boolean> => {
};

export const runSpeedTest = async (): Promise<void> => {
let usedRunner;
if (CONFIG.accept_ookla_eula && (await commandExists('speedtest_ookla'))) {
usedRunner = 'ookla';
const { stdout } = await exec('speedtest_ookla -f json');
const json = JSON.parse(stdout);

Expand All @@ -155,6 +157,7 @@ export const runSpeedTest = async (): Promise<void> => {
STATIC_INFO.network.publicIp =
json.interface.externalIp ?? STATIC_INFO.network.publicIp;
} else if (await commandExists('speedtest')) {
usedRunner = 'speedtest-cli';
const { stdout } = await exec('speedtest --json');
const json = JSON.parse(stdout);

Expand All @@ -164,6 +167,7 @@ export const runSpeedTest = async (): Promise<void> => {
STATIC_INFO.network.publicIp =
json.client.ip ?? STATIC_INFO.network.publicIp;
} else {
usedRunner = 'universal';
const universalSpeedtest = new UniversalSpeedtest({
measureUpload: true,
downloadUnit: SpeedUnits.bps,
Expand All @@ -180,7 +184,7 @@ export const runSpeedTest = async (): Promise<void> => {
speed.client.ip ?? STATIC_INFO.network.publicIp;
}

console.log('Speed-test result:', STATIC_INFO.network);
return usedRunner;
};

export const loadStaticServerInfo = async (): Promise<void> => {
Expand Down

0 comments on commit 26267b2

Please sign in to comment.