Fix version check in server.js template with error handling

Added robust error handling for dynamic version retrieval in the server.js template:
- Added try/catch block around package.json require
- Added fallback version if package.json can't be loaded
- Ensures server will start even if there's an issue loading the version

This prevents connection errors related to the version check functionality.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-05 10:33:01 +00:00
parent 16a7c0c0b6
commit 484a021936

View File

@ -266,8 +266,13 @@ app.use(bodyParser.urlencoded({ extended: true, limit: '50mb' }));
//============================== //==============================
// Get the version from package.json // Get the version from package.json
const packageJson = require('./package.json'); let appVersion = '2.0.6'; // Default fallback version
const appVersion = packageJson.version; try {
const packageJson = require('./package.json');
appVersion = packageJson.version;
} catch (err) {
console.warn('Could not read version from package.json, using default');
}
// Server status API // Server status API
app.get('/api/status', (req, res) => { app.get('/api/status', (req, res) => {