@pixelbyte-software/pixcode 1.31.11 → 1.31.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/server/index.js
CHANGED
|
@@ -600,16 +600,56 @@ app.post('/api/system/update', authenticateToken, async (req, res) => {
|
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
602
|
|
|
603
|
+
// Short-circuit for "already on latest" in the npm-global path so
|
|
604
|
+
// users don't accidentally crash their own daemon by clicking Update
|
|
605
|
+
// while already up to date. The runtime-dir branch above already has
|
|
606
|
+
// this guard (line ~504); replicate it for npm mode. Git mode skips
|
|
607
|
+
// this since `git pull` is harmless when already up to date.
|
|
608
|
+
if (!IS_PLATFORM && installMode === 'npm') {
|
|
609
|
+
try {
|
|
610
|
+
send('log', { stream: 'meta', chunk: 'Querying registry for latest version…\n' });
|
|
611
|
+
const registryRes = await fetch('https://registry.npmjs.org/@pixelbyte-software/pixcode');
|
|
612
|
+
if (registryRes.ok) {
|
|
613
|
+
const metadata = await registryRes.json();
|
|
614
|
+
const latestVersion = metadata['dist-tags']?.latest;
|
|
615
|
+
if (latestVersion && latestVersion === SERVER_VERSION) {
|
|
616
|
+
send('log', { stream: 'meta', chunk: `Already on ${SERVER_VERSION} — nothing to do.\n` });
|
|
617
|
+
send('done', {
|
|
618
|
+
success: true,
|
|
619
|
+
version: SERVER_VERSION,
|
|
620
|
+
alreadyLatest: true,
|
|
621
|
+
message: 'Already on the latest version.',
|
|
622
|
+
});
|
|
623
|
+
endStream();
|
|
624
|
+
return;
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
} catch (err) {
|
|
628
|
+
// Registry unreachable — fall through to the install attempt
|
|
629
|
+
// rather than block the user. Log and continue.
|
|
630
|
+
console.warn('[update] Registry precheck failed:', (err && err.message) || err);
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
603
634
|
send('log', { stream: 'meta', chunk: `Running: ${updateCommand}\n` });
|
|
604
635
|
|
|
605
|
-
// Cross-platform shell invocation.
|
|
606
|
-
//
|
|
607
|
-
//
|
|
636
|
+
// Cross-platform shell invocation. `detached: true` + `unref()` below
|
|
637
|
+
// means the install child survives if this server process gets killed
|
|
638
|
+
// mid-install (which is common on Linux when `npm install -g`
|
|
639
|
+
// overwrites the running package's own files — the running process
|
|
640
|
+
// can segfault or the supervisor kills it). Without detachment, a
|
|
641
|
+
// killed parent tears down the npm child too and users end up with
|
|
642
|
+
// a half-installed package and no server at all.
|
|
608
643
|
const child = spawn(updateCommand, {
|
|
609
644
|
cwd: updateCwd,
|
|
610
645
|
env: process.env,
|
|
611
646
|
shell: true,
|
|
647
|
+
detached: true,
|
|
648
|
+
stdio: ['ignore', 'pipe', 'pipe'],
|
|
612
649
|
});
|
|
650
|
+
// Don't hold a reference that keeps the event loop alive or ties the
|
|
651
|
+
// child's lifetime to ours — we want it to outlive a daemon restart.
|
|
652
|
+
try { child.unref(); } catch { /* noop */ }
|
|
613
653
|
|
|
614
654
|
let clientAborted = false;
|
|
615
655
|
req.on('close', () => {
|
|
@@ -2518,6 +2558,25 @@ app.get(/.*/, (req, res) => {
|
|
|
2518
2558
|
return res.status(404).send('Not found');
|
|
2519
2559
|
}
|
|
2520
2560
|
|
|
2561
|
+
// Never serve index.html for unmatched API / WS routes — returning HTML
|
|
2562
|
+
// there gives the frontend a bogus 200 + `<!doctype ...` body, which
|
|
2563
|
+
// then explodes `res.json()` as "Unexpected token '<'". Sending a real
|
|
2564
|
+
// JSON 404 here means missing endpoints surface as a clear HTTP error
|
|
2565
|
+
// instead of a misleading parse failure. Fixes the Settings → Agents →
|
|
2566
|
+
// Configuration tab on hosts still running an older backend that
|
|
2567
|
+
// predates `/api/providers/:p/config-files`.
|
|
2568
|
+
if (req.path.startsWith('/api/') || req.path === '/api' ||
|
|
2569
|
+
req.path.startsWith('/ws') || req.path.startsWith('/shell') ||
|
|
2570
|
+
req.path === '/health') {
|
|
2571
|
+
return res.status(404).json({
|
|
2572
|
+
success: false,
|
|
2573
|
+
error: {
|
|
2574
|
+
code: 'ROUTE_NOT_FOUND',
|
|
2575
|
+
message: `No handler for ${req.method} ${req.path}. The backend may be an older build — restart the server after an update.`,
|
|
2576
|
+
},
|
|
2577
|
+
});
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2521
2580
|
// Only serve index.html for HTML routes, not for static assets
|
|
2522
2581
|
// Static assets should already be handled by express.static middleware above
|
|
2523
2582
|
const indexPath = path.join(APP_ROOT, 'dist', 'index.html');
|