From 3c898006a69939ba7f257daefef283f249549d4c Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Sun, 20 Apr 2025 20:02:55 +0100 Subject: [PATCH] feat: Add version display to frontend --- package.json | 2 +- public/app.js | 17 +++++++++++++++++ public/index.html | 3 +++ server/index.js | 17 +++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 5d0f1693b..cab439efb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "proxmox-simplified", - "version": "1.0.0", + "version": "2.0.0", "description": "Simplified monitor for Proxmox", "scripts": { "dev": "NODE_ENV=development cd server && node index.js", diff --git a/public/app.js b/public/app.js index 299973b31..9fc04a1f3 100644 --- a/public/app.js +++ b/public/app.js @@ -39,6 +39,7 @@ document.addEventListener('DOMContentLoaded', function() { const tooltipElement = document.getElementById('custom-tooltip'); const searchInput = document.getElementById('dashboard-search'); const statusElement = document.getElementById('dashboard-status-text'); + const versionSpan = document.getElementById('app-version'); // Get version span if (!connectionStatus) { console.error('Critical element #connection-status not found!'); @@ -842,4 +843,20 @@ document.addEventListener('DOMContentLoaded', function() { updateSortUI('main-table', document.querySelector('#main-table th[data-sort="id"]')); // Data is requested on socket 'connect' event + // --- Fetch and display version --- + fetch('/api/version') + .then(response => response.json()) + .then(data => { + if (versionSpan && data.version) { + versionSpan.textContent = data.version; + } + }) + .catch(error => { + console.error('Error fetching version:', error); + if (versionSpan) { + versionSpan.textContent = 'error'; + } + }); + // --- End fetch version --- + }); // End DOMContentLoaded \ No newline at end of file diff --git a/public/index.html b/public/index.html index 3c6717160..2666ade12 100644 --- a/public/index.html +++ b/public/index.html @@ -215,5 +215,8 @@ + \ No newline at end of file diff --git a/server/index.js b/server/index.js index 7fe5deeba..b4193d593 100644 --- a/server/index.js +++ b/server/index.js @@ -39,6 +39,7 @@ if (missingVars.length > 0 || placeholderVars.length > 0) { } // --- END Environment Variable Validation --- +const fs = require('fs'); // Add fs module const express = require('express'); const http = require('http'); const path = require('path'); @@ -116,6 +117,22 @@ app.use(cors()); app.use(express.json()); app.use(express.static(path.join(__dirname, '../public'))); +// --- Add API endpoint for version --- +let appVersion = 'unknown'; +try { + const packageJsonPath = path.join(__dirname, '../package.json'); + const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf8'); + const packageJson = JSON.parse(packageJsonContent); + appVersion = packageJson.version || 'unknown'; +} catch (error) { + console.error('Error reading version from package.json:', error.message); +} + +app.get('/api/version', (req, res) => { + res.json({ version: appVersion }); +}); +// --- End API endpoint --- + // Create HTTP server const server = http.createServer(app);