Add "(APIReq)" to API requests to make them easier to see in logs

This commit is contained in:
Holly Stubbs 2022-01-07 04:54:39 +00:00
parent bfe6676867
commit 3a3fee6283
Signed by: tgpholly
GPG key ID: B8583C4B7D18119E

20
EUS.js
View file

@ -361,13 +361,12 @@ module.exports = {
async function handleAPI(req, res) { async function handleAPI(req, res) {
const startTime = Date.now(); const startTime = Date.now();
let jsonaa = {}, filesaa = 0, spaceaa = 0, endTime = 0; let jsonaa = {}, filesaa = 0, spaceaa = 0;
switch (req.url.split("?")[0]) { switch (req.url.split("?")[0]) {
// Status check to see the online status of EUS // Status check to see the online status of EUS
// Used by ESL to make sure EUS is online // Used by ESL to make sure EUS is online
case "/api/get-server-status": case "/api/get-server-status":
endTime = Date.now(); global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} (APIReq) ${req.url} ${Date.now() - startTime}ms`);
global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`);
return res.end('{"status":1,"version":"'+global.internals.version+'"}'); return res.end('{"status":1,"version":"'+global.internals.version+'"}');
/* Stats api endpoint /* Stats api endpoint
@ -384,39 +383,34 @@ async function handleAPI(req, res) {
if (filesaa == 1) { if (filesaa == 1) {
// If getting the space used on the server isn't required send the json // If getting the space used on the server isn't required send the json
if (spaceaa != 1) { if (spaceaa != 1) {
endTime = Date.now(); global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} (APIReq) ${req.url} ${Date.now() - startTime}ms`);
global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`);
delete jsonaa["space"]; delete jsonaa["space"];
return res.end(JSON.stringify(jsonaa)); return res.end(JSON.stringify(jsonaa));
} }
} }
// Getting space is required // Getting space is required
if (spaceaa == 1) { if (spaceaa == 1) {
endTime = Date.now(); global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} (APIReq) ${req.url} ${Date.now() - startTime}ms`);
global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`);
if (filesaa != 1) delete jsonaa["files"]; if (filesaa != 1) delete jsonaa["files"];
return res.end(JSON.stringify(jsonaa)); return res.end(JSON.stringify(jsonaa));
} }
if (filesaa != 1 && spaceaa != 1) { if (filesaa != 1 && spaceaa != 1) {
endTime = Date.now(); global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} (APIReq) ${req.url} ${Date.now() - startTime}ms`);
global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`);
return res.end("Please add f and or s to your queries to get the files and space"); return res.end("Please add f and or s to your queries to get the files and space");
} }
break; break;
// Information API // Information API
case "/api/get-info": case "/api/get-info":
endTime = Date.now(); global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} (APIReq) ${req.url} ${Date.now() - startTime}ms`);
global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`);
return res.end(JSON.stringify({ return res.end(JSON.stringify({
version: global.internals.version, version: global.internals.version,
instance: config["server"]["instance_type"] instance: config["server"]["instance_type"]
})); }));
default: default:
endTime = Date.now(); global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} (APIReq) ${req.url} ${Date.now() - startTime}ms`);
global.modules.consoleHelper.printInfo(emoji.heavy_check, `${req.method}: ${chalk.green("[200]")} ${req.url} ${endTime - startTime}ms`);
return res.send(` return res.send(`
<h2>All currently avaliable api endpoints</h2> <h2>All currently avaliable api endpoints</h2>
<a href="/api/get-server-status">/api/get-server-status</a> <a href="/api/get-server-status">/api/get-server-status</a>