Add json api

This commit is contained in:
Christopher Cookman 2025-03-17 23:11:07 -06:00
parent 3fa6a199ee
commit 14837275b9

View file

@ -145,6 +145,18 @@ function renderStatusPage() {
fs.writeFileSync(process.env.DEV ? "./dev/index.html" : "/var/www/html/status/index.html", str);
}
});
const jsonOutput = {
endpoints: parseEndpoints(getEndpoints()),
userInfo: Object.fromEntries(Object.entries(getUsers()).map(([key, value]) => [key, value[1]]))
};
jsonOutput.endpoints.forEach(endpoint => {
const avgPing = endpoint.contacts.reduce((sum, contact) => sum + contact.ping, 0) / endpoint.contacts.length;
endpoint.contacts = [{ ping: isNaN(avgPing) ? 'No Data' : avgPing.toFixed(2) }];
});
fs.writeFileSync(process.env.DEV ? "./dev/status.json" : "/var/www/html/status/status.json", JSON.stringify(jsonOutput, null, 2));
}
client.on("ready", () => {