From c88040084a53c189acd3c1052702cf4866de4a5a Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Tue, 13 Jan 2026 18:03:01 +0100 Subject: [PATCH] Improve server startup logging and update script fetching (#443) Adds success and error logging to the Next.js app preparation process in server.js, including guidance for missing production builds. In versionRouter, always fetches the latest update.sh from GitHub before running updates, logging the outcome and falling back to the local script if fetching fails. --- server.js | 6 ++++++ src/server/api/routers/version.ts | 21 +++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/server.js b/server.js index 864acf7..0a26373 100644 --- a/server.js +++ b/server.js @@ -1610,6 +1610,7 @@ class ScriptExecutionHandler { // TerminalHandler removed - not used by current application app.prepare().then(() => { + console.log('> Next.js app prepared successfully'); const httpServer = createServer(async (req, res) => { try { // Be sure to pass `true` as the second argument to `url.parse`. @@ -1715,4 +1716,9 @@ app.prepare().then(() => { autoSyncModule.setupGracefulShutdown(); } }); +}).catch((err) => { + console.error('> Failed to start server:', err.message); + console.error('> If you see "Could not find a production build", run: npm run build'); + console.error('> Full error:', err); + process.exit(1); }); diff --git a/src/server/api/routers/version.ts b/src/server/api/routers/version.ts index 31acad4..adde7dc 100644 --- a/src/server/api/routers/version.ts +++ b/src/server/api/routers/version.ts @@ -238,6 +238,27 @@ export const versionRouter = createTRPCRouter({ // Clear/create the log file await writeFile(logPath, '', 'utf-8'); + // Always fetch the latest update.sh from GitHub before running + // This ensures we always use the newest update script, avoiding + // the "chicken-and-egg" problem where old scripts can't update properly + const updateScriptUrl = 'https://raw.githubusercontent.com/community-scripts/ProxmoxVE-Local/main/update.sh'; + try { + const response = await fetch(updateScriptUrl); + if (response.ok) { + const latestScript = await response.text(); + await writeFile(updateScriptPath, latestScript, { mode: 0o755 }); + // Log that we fetched the latest script + await writeFile(logPath, '[INFO] Fetched latest update.sh from GitHub\n', { flag: 'a' }); + } else { + // If fetch fails, log warning but continue with local script + await writeFile(logPath, `[WARNING] Could not fetch latest update.sh (HTTP ${response.status}), using local version\n`, { flag: 'a' }); + } + } catch (fetchError) { + // If fetch fails, log warning but continue with local script + const errorMsg = fetchError instanceof Error ? fetchError.message : 'Unknown error'; + await writeFile(logPath, `[WARNING] Could not fetch latest update.sh: ${errorMsg}, using local version\n`, { flag: 'a' }); + } + // Spawn the update script as a detached process using nohup // This allows it to run independently and kill the parent Node.js process // Redirect output to log file