diff --git a/backend/Dockerfile b/backend/Dockerfile index 96a6106..eafdbda 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -57,6 +57,10 @@ ENV PING_COUNT=4 ENV GEOIP_CITY_DB=./data/GeoLite2-City.mmdb ENV GEOIP_ASN_DB=./data/GeoLite2-ASN.mmdb +# Define build argument and environment variable for Git commit SHA +ARG GIT_COMMIT_SHA=unknown +ENV GIT_COMMIT_SHA=${GIT_COMMIT_SHA} + # Run the app when the container launches CMD ["node", "server.js"] \ No newline at end of file diff --git a/backend/server.js b/backend/server.js index 91ec06f..1ff9ffa 100644 --- a/backend/server.js +++ b/backend/server.js @@ -611,6 +611,14 @@ app.get('/api/lookup', async (req, res) => { } }); +// Version Endpunkt +app.get('/api/version', (req, res) => { + const commitSha = process.env.GIT_COMMIT_SHA || 'unknown'; + logger.info({ commitSha }, 'Version request received'); + res.json({ commitSha }); +}); + + // --- Server starten --- initialize().then(() => { app.listen(PORT, () => { @@ -620,6 +628,7 @@ initialize().then(() => { logger.info(` http://localhost:${PORT}/api/ping?targetIp=`); logger.info(` http://localhost:${PORT}/api/traceroute?targetIp=`); logger.info(` http://localhost:${PORT}/api/lookup?targetIp=`); + logger.info(` http://localhost:${PORT}/api/version`); }); }).catch(error => { // Fehler bei der Initialisierung wurde bereits geloggt. diff --git a/compose.yml b/compose.yml index 8704fd9..2c44431 100644 --- a/compose.yml +++ b/compose.yml @@ -1,7 +1,12 @@ services: # Backend Service (Node.js App) backend: - build: ./backend # Pfad zum Verzeichnis mit dem Backend-Dockerfile + build: + context: ./backend # Pfad zum Verzeichnis mit dem Backend-Dockerfile + args: + # Übergibt den Git Commit Hash als Build-Argument. + # Erwartet, dass GIT_COMMIT_SHA in der Shell-Umgebung gesetzt ist (z.B. export GIT_COMMIT_SHA=$(git rev-parse --short HEAD)) + - GIT_COMMIT_SHA=${GIT_COMMIT_SHA:-unknown} container_name: utools_backend # Eindeutiger Name für den Container restart: unless-stopped environment: diff --git a/frontend/index.html b/frontend/index.html index 308a29c..a8f8693 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -207,6 +207,12 @@ + +
+

Version: loading...

+
+ + diff --git a/frontend/script.js b/frontend/script.js index ecaed0d..dd58f78 100644 --- a/frontend/script.js +++ b/frontend/script.js @@ -66,6 +66,9 @@ document.addEventListener('DOMContentLoaded', () => { const tracerouteLoader = document.getElementById('traceroute-loader'); const tracerouteMessage = document.getElementById('traceroute-message'); + // --- DOM Elements (Footer) --- + const commitShaEl = document.getElementById('commit-sha'); + // --- Configuration --- const API_BASE_URL = '/api'; // Anpassen, falls nötig @@ -260,6 +263,22 @@ document.addEventListener('DOMContentLoaded', () => { } } + /** Ruft die Versionsinformationen (Commit SHA) ab */ + async function fetchVersionInfo() { + try { + const response = await fetch(`${API_BASE_URL}/version`); + if (!response.ok) throw new Error(`Network response: ${response.statusText} (${response.status})`); + const data = await response.json(); + console.log('Received Version Info:', data); + if (commitShaEl) { + commitShaEl.textContent = data.commitSha || 'unknown'; + } + } catch (error) { + console.error('Failed to fetch version info:', error); + if (commitShaEl) commitShaEl.textContent = 'error'; + } + } + // --- Lookup Functions --- /** Zeigt Fehler im Lookup-Bereich an */ @@ -562,6 +581,7 @@ document.addEventListener('DOMContentLoaded', () => { // --- Initial Load & Event Listeners --- fetchIpInfo(); // Lade Infos zur eigenen IP + fetchVersionInfo(); // Lade Versionsinfo für Footer lookupButton.addEventListener('click', handleLookupClick); lookupIpInput.addEventListener('keypress', (event) => {