From fc3329597d50241f9dfa26e618fb034b9f47e257 Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 1 Jan 2023 19:15:52 -0700 Subject: [PATCH] Add details about the project itself to the / endpoint --- index.js | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 8b0a4e2..9b27365 100644 --- a/index.js +++ b/index.js @@ -15,6 +15,7 @@ const Steam = require("steam-server-query") const express = require('express'); const colors = require("colors"); const semver = require("semver"); +const childProcess = require('child_process'); const app = express(); const port = 3004; const config = require("./config.json"); @@ -116,6 +117,29 @@ function countdown(seconds, start, end) { }); } +function getGitCommitDetails() { + try { + // Use child_process.execSync to run the `git log -1 --format=%H%x09%an%x09%ae%x09%ad%x09%s` command + // and return the output as a string + const stdout = childProcess.execSync('git log -1 --format=%H%x09%an%x09%ae%x09%ad%x09%s').toString(); + + // Split the output string into an array of fields + const fields = stdout.split('\t'); + + // Return the commit details as a JSON object + return { + hash: fields[0].substring(0, 7), + fullHash: fields[0], + author: fields[1], + email: fields[2], + timestamp: fields[3], + subject: fields[4], + }; + } catch (error) { + console.error(error); + } +} + function objectLength(object) { var length = 0; for (var key in object) { @@ -308,6 +332,11 @@ function purgeDeadServers() { console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Purged ${counter} dead servers!`); } +// Startup messages +console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Starting Stormworks Server List...`); +console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Config: ${JSON.stringify(config)}`); +console.log(`${colors.cyan(`[INFO ${new Date()}]`)} Commit: ${getGitCommitDetails().hash}`); + // Update master list every 1 minute setInterval(() => { updateMasterList(); @@ -388,7 +417,12 @@ app.get('/', (req, res) => { "endpoints": [ "/check?address=IP:PORT", "/serverList" - ] + ], + "about": { + "author": "Chris Chrome", + "repo": "https://github.com/TerraDevelopers/TerraStatusAPI", + "commit": getGitCommitDetails() + } })); });