fix: rebuild bundle with widget, restore TOTP across container recreate, integrate auto-updater changes
Three logical changes grouped:
1. Widget bundle rebuild + sami-files logo (from previous session)
- status/dist/{init,core,features,onboarding}.js rebuilt from latest source
- status/sw.js cache bumped to dashcaddy-shell-594ec75648 to force SW refresh
- status/assets/sami-files.png added (Sami Files service card logo)
2. status/build.js: include monitoring-widgets.js in bundle
- The original build.js was missing monitoring-widgets.js from its JS()
bundle list — that's why the System Overview widget never showed up
in the live init.js until we ran the live /var/www/dashcaddy-status/
build.js. Now consistent.
3. dashcaddy-api/scripts/dashcaddy-update.sh restart_container(): preserve
TOTP secret across container recreates
- Was only setting SERVICES_FILE; container fell back to image-local
/app/credentials.json + /app/.encryption-key (auto-generated fresh
every recreate), which broke TOTP for the bind-mounted secret at
/app/data/credentials.json
- Added CREDENTIALS_FILE + ENCRYPTION_KEY_FILE env vars pointing at
/app/data/ so the container reads from the bind-mounted host data dir
- See skill: software-development/dashcaddy/references/totp-and-system-overview-pitfalls.md §9
4. Auto-updater integration (pulled from upstream release):
- dashcaddy-api/VERSION: dev → c64bbe2
- dashcaddy-api/health-checker.js, middleware.js, package.json,
routes/backups.js, src/app.js: new release code (bundled workflows,
/api/auth/ → /api/v1/ back-compat rewrite, backup storage limits)
This commit is contained in:
@@ -1 +1 @@
|
|||||||
dev
|
c64bbe2
|
||||||
|
|||||||
@@ -9,9 +9,24 @@ const http = require('http');
|
|||||||
const EventEmitter = require('events');
|
const EventEmitter = require('events');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const paths = require('./platform-paths');
|
||||||
|
|
||||||
const HEALTH_CONFIG_FILE = process.env.HEALTH_CONFIG_FILE || path.join(__dirname, 'health-config.json');
|
// Persist health config + history alongside the other state files (services.json,
|
||||||
const HEALTH_HISTORY_FILE = process.env.HEALTH_HISTORY_FILE || path.join(__dirname, 'health-history.json');
|
// config.json) rather than next to the source. In a container that data dir is the
|
||||||
|
// mounted /app/data volume, so uptime history survives container recreates/updates;
|
||||||
|
// previously these defaulted to __dirname (unmounted /app) and every recreate wiped
|
||||||
|
// the accumulated history, blanking the dashboard uptime bars. Explicit env vars
|
||||||
|
// still override.
|
||||||
|
const HEALTH_DATA_DIR = process.env.HEALTH_DATA_DIR || path.dirname(paths.configFile);
|
||||||
|
const HEALTH_CONFIG_FILE = process.env.HEALTH_CONFIG_FILE || path.join(HEALTH_DATA_DIR, 'health-config.json');
|
||||||
|
const HEALTH_HISTORY_FILE = process.env.HEALTH_HISTORY_FILE || path.join(HEALTH_DATA_DIR, 'health-history.json');
|
||||||
|
|
||||||
|
// Legacy locations (next to the source) used before the data-dir default. Read these
|
||||||
|
// once on first load if the new files are absent, so upgrading installs migrate their
|
||||||
|
// accumulated history/config instead of starting empty. The next save() rewrites to
|
||||||
|
// the new location.
|
||||||
|
const LEGACY_HEALTH_CONFIG_FILE = path.join(__dirname, 'health-config.json');
|
||||||
|
const LEGACY_HEALTH_HISTORY_FILE = path.join(__dirname, 'health-history.json');
|
||||||
const CHECK_INTERVAL = parseInt(process.env.HEALTH_CHECK_INTERVAL || '30000', 10); // 30 seconds
|
const CHECK_INTERVAL = parseInt(process.env.HEALTH_CHECK_INTERVAL || '30000', 10); // 30 seconds
|
||||||
const MAX_CHECK_INTERVAL = parseInt(process.env.HEALTH_CHECK_MAX_INTERVAL || '300000', 10); // 5 minutes max backoff
|
const MAX_CHECK_INTERVAL = parseInt(process.env.HEALTH_CHECK_MAX_INTERVAL || '300000', 10); // 5 minutes max backoff
|
||||||
const HISTORY_RETENTION_DAYS = parseInt(process.env.HEALTH_HISTORY_RETENTION || '30', 10);
|
const HISTORY_RETENTION_DAYS = parseInt(process.env.HEALTH_HISTORY_RETENTION || '30', 10);
|
||||||
@@ -541,8 +556,10 @@ class HealthChecker extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
loadConfig() {
|
loadConfig() {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(HEALTH_CONFIG_FILE)) {
|
const file = fs.existsSync(HEALTH_CONFIG_FILE) ? HEALTH_CONFIG_FILE
|
||||||
return JSON.parse(fs.readFileSync(HEALTH_CONFIG_FILE, 'utf8'));
|
: (HEALTH_CONFIG_FILE !== LEGACY_HEALTH_CONFIG_FILE && fs.existsSync(LEGACY_HEALTH_CONFIG_FILE) ? LEGACY_HEALTH_CONFIG_FILE : null);
|
||||||
|
if (file) {
|
||||||
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.emit('log', 'error', `Error loading config: ${error.message}`);
|
this.emit('log', 'error', `Error loading config: ${error.message}`);
|
||||||
@@ -566,8 +583,10 @@ class HealthChecker extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
loadHistory() {
|
loadHistory() {
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync(HEALTH_HISTORY_FILE)) {
|
const file = fs.existsSync(HEALTH_HISTORY_FILE) ? HEALTH_HISTORY_FILE
|
||||||
return JSON.parse(fs.readFileSync(HEALTH_HISTORY_FILE, 'utf8'));
|
: (HEALTH_HISTORY_FILE !== LEGACY_HEALTH_HISTORY_FILE && fs.existsSync(LEGACY_HEALTH_HISTORY_FILE) ? LEGACY_HEALTH_HISTORY_FILE : null);
|
||||||
|
if (file) {
|
||||||
|
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.emit('log', 'error', `Error loading history: ${error.message}`);
|
this.emit('log', 'error', `Error loading history: ${error.message}`);
|
||||||
|
|||||||
@@ -304,6 +304,15 @@ module.exports = function configureMiddleware(app, {
|
|||||||
{ path: '/api/v1/license/feature/', prefix: true, method: 'GET' },
|
{ path: '/api/v1/license/feature/', prefix: true, method: 'GET' },
|
||||||
{ path: '/api/v1/config', exact: true, method: 'GET' },
|
{ path: '/api/v1/config', exact: true, method: 'GET' },
|
||||||
{ path: '/api/v1/services/status', exact: true, method: 'GET' },
|
{ path: '/api/v1/services/status', exact: true, method: 'GET' },
|
||||||
|
{ path: '/api/v1/health-checks/status', exact: true, method: 'GET' },
|
||||||
|
// Read-only update/version info shown on the dashboard view (verification
|
||||||
|
// modal, topbar version, update badges). Mutating actions — update-apply,
|
||||||
|
// rollback (POST) — are NOT listed here and stay TOTP-protected.
|
||||||
|
{ path: '/api/v1/system/version', exact: true, method: 'GET' },
|
||||||
|
{ path: '/api/v1/system/update-status', exact: true, method: 'GET' },
|
||||||
|
{ path: '/api/v1/system/update-history', exact: true, method: 'GET' },
|
||||||
|
{ path: '/api/v1/system/update-check', exact: true, method: 'GET' },
|
||||||
|
{ path: '/api/v1/updates/available', exact: true, method: 'GET' },
|
||||||
{ path: '/api/v1/system/update-notify', exact: true, method: 'POST' },
|
{ path: '/api/v1/system/update-notify', exact: true, method: 'POST' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dashcaddy-api",
|
"name": "dashcaddy-api",
|
||||||
"version": "1.6.0",
|
"version": "1.7.8",
|
||||||
"description": "DashCaddy API server - Dashboard backend for Docker, Caddy & DNS management",
|
"description": "DashCaddy API server - Dashboard backend for Docker, Caddy & DNS management",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const { success } = require('../response-helpers');
|
const fsp = require('fs').promises;
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
const { success } = require('../response-helpers');
|
||||||
|
|
||||||
const DEFAULT_BACKUP_DIR = process.env.BACKUP_DIR || path.join(__dirname, 'backups');
|
const DEFAULT_BACKUP_DIR = process.env.BACKUP_DIR || path.join(__dirname, '..', 'backups');
|
||||||
|
const DEFAULT_MAX_STORAGE_BYTES = process.env.BACKUP_MAX_STORAGE_BYTES
|
||||||
|
? parseInt(process.env.BACKUP_MAX_STORAGE_BYTES, 10)
|
||||||
|
: 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Backups routes factory
|
* Backups routes factory
|
||||||
@@ -41,6 +45,7 @@ module.exports = function({ backupManager, licenseManager, asyncHandler }) {
|
|||||||
runImmediately: backup.runImmediately || false,
|
runImmediately: backup.runImmediately || false,
|
||||||
destination: backup.destination || 'local',
|
destination: backup.destination || 'local',
|
||||||
destinationPath: backup.destinationPath || DEFAULT_BACKUP_DIR,
|
destinationPath: backup.destinationPath || DEFAULT_BACKUP_DIR,
|
||||||
|
maxStorageBytes: backup.maxStorageBytes || null,
|
||||||
lastRun: lastRun ? lastRun.toISOString() : null,
|
lastRun: lastRun ? lastRun.toISOString() : null,
|
||||||
nextRun: nextRun ? nextRun.toISOString() : null,
|
nextRun: nextRun ? nextRun.toISOString() : null,
|
||||||
lastBackupId: appHistory.length > 0 ? appHistory[0].id : null
|
lastBackupId: appHistory.length > 0 ? appHistory[0].id : null
|
||||||
@@ -52,7 +57,7 @@ module.exports = function({ backupManager, licenseManager, asyncHandler }) {
|
|||||||
|
|
||||||
// Create or update a scheduled backup for an app
|
// Create or update a scheduled backup for an app
|
||||||
router.post('/backups/schedule', premiumGating, asyncHandler(async (req, res) => {
|
router.post('/backups/schedule', premiumGating, asyncHandler(async (req, res) => {
|
||||||
const { appId, enabled, schedule, retention, runImmediately, destination, destinationPath } = req.body;
|
const { appId, enabled, schedule, retention, runImmediately, destination, destinationPath, maxStorageBytes } = req.body;
|
||||||
|
|
||||||
if (!appId) {
|
if (!appId) {
|
||||||
const { ValidationError } = require('../errors');
|
const { ValidationError } = require('../errors');
|
||||||
@@ -62,6 +67,11 @@ module.exports = function({ backupManager, licenseManager, asyncHandler }) {
|
|||||||
const config = backupManager.getConfig();
|
const config = backupManager.getConfig();
|
||||||
if (!config.backups) config.backups = {};
|
if (!config.backups) config.backups = {};
|
||||||
|
|
||||||
|
// Parse maxStorageBytes if provided as string (e.g. "10GB")
|
||||||
|
const parsedMaxStorage = maxStorageBytes
|
||||||
|
? (typeof maxStorageBytes === 'string' ? parseStorageSize(maxStorageBytes) : maxStorageBytes)
|
||||||
|
: null;
|
||||||
|
|
||||||
// Build the backup config for this app
|
// Build the backup config for this app
|
||||||
const backupConfig = {
|
const backupConfig = {
|
||||||
enabled: enabled !== undefined ? enabled : true,
|
enabled: enabled !== undefined ? enabled : true,
|
||||||
@@ -71,7 +81,8 @@ module.exports = function({ backupManager, licenseManager, asyncHandler }) {
|
|||||||
destination: destination || 'local',
|
destination: destination || 'local',
|
||||||
destinationPath: destinationPath || DEFAULT_BACKUP_DIR,
|
destinationPath: destinationPath || DEFAULT_BACKUP_DIR,
|
||||||
include: ['all'],
|
include: ['all'],
|
||||||
destinations: [{ type: destination || 'local', path: destinationPath || DEFAULT_BACKUP_DIR }]
|
destinations: [{ type: destination || 'local', path: destinationPath || DEFAULT_BACKUP_DIR }],
|
||||||
|
maxStorageBytes: parsedMaxStorage
|
||||||
};
|
};
|
||||||
|
|
||||||
config.backups[appId] = backupConfig;
|
config.backups[appId] = backupConfig;
|
||||||
@@ -490,6 +501,39 @@ module.exports = function({ backupManager, licenseManager, asyncHandler }) {
|
|||||||
success(res, { history });
|
success(res, { history });
|
||||||
}, 'backups-history'));
|
}, 'backups-history'));
|
||||||
|
|
||||||
|
// Get storage info for backups destination
|
||||||
|
router.get('/backups/storage-info', asyncHandler(async (req, res) => {
|
||||||
|
const storageInfo = await getStorageInfo();
|
||||||
|
success(res, storageInfo);
|
||||||
|
}, 'backups-storage-info'));
|
||||||
|
|
||||||
|
// Schedule a backup
|
||||||
|
router.post('/backups/schedule', asyncHandler(async (req, res) => {
|
||||||
|
const { name, schedule, maxStorageBytes, ...backupConfig } = req.body;
|
||||||
|
|
||||||
|
if (!name || !schedule) {
|
||||||
|
return res.status(400).json({ error: 'name and schedule are required' });
|
||||||
|
}
|
||||||
|
|
||||||
|
const config = backupManager.getConfig();
|
||||||
|
|
||||||
|
// Store maxStorageBytes in the backup config (converted to bytes)
|
||||||
|
const maxBytes = typeof maxStorageBytes === 'number' && maxStorageBytes > 0
|
||||||
|
? maxStorageBytes
|
||||||
|
: (typeof maxStorageBytes === 'string' ? parseStorageSize(maxStorageBytes) : 0);
|
||||||
|
|
||||||
|
config.backups[name] = {
|
||||||
|
...backupConfig,
|
||||||
|
enabled: true,
|
||||||
|
schedule,
|
||||||
|
maxStorageBytes: maxBytes,
|
||||||
|
destinations: backupConfig.destinations || [{ type: 'local' }]
|
||||||
|
};
|
||||||
|
|
||||||
|
backupManager.updateConfig(config);
|
||||||
|
success(res, { message: `Backup '${name}' scheduled`, maxStorageBytes: maxBytes });
|
||||||
|
}, 'backups-schedule'));
|
||||||
|
|
||||||
// Restore from backup
|
// Restore from backup
|
||||||
router.post('/backups/restore/:backupId', asyncHandler(async (req, res) => {
|
router.post('/backups/restore/:backupId', asyncHandler(async (req, res) => {
|
||||||
const result = await backupManager.restoreBackup(req.params.backupId, req.body);
|
const result = await backupManager.restoreBackup(req.params.backupId, req.body);
|
||||||
@@ -653,3 +697,121 @@ function formatBytes(bytes) {
|
|||||||
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
||||||
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get storage information for the backup directory
|
||||||
|
*/
|
||||||
|
async function getStorageInfo() {
|
||||||
|
const result = {
|
||||||
|
destination: DEFAULT_BACKUP_DIR,
|
||||||
|
maxStorageBytes: DEFAULT_MAX_STORAGE_BYTES,
|
||||||
|
usedBytes: 0,
|
||||||
|
availableBytes: 0,
|
||||||
|
usagePercent: 0,
|
||||||
|
backupCount: 0,
|
||||||
|
oldestBackup: null,
|
||||||
|
newestBackup: null
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Get disk space info
|
||||||
|
const diskSpace = await getDiskSpaceInfo(DEFAULT_BACKUP_DIR);
|
||||||
|
result.availableBytes = diskSpace.available;
|
||||||
|
|
||||||
|
// Scan for backup files
|
||||||
|
if (DEFAULT_MAX_STORAGE_BYTES > 0) {
|
||||||
|
result.maxStorageBytes = DEFAULT_MAX_STORAGE_BYTES;
|
||||||
|
} else {
|
||||||
|
result.maxStorageBytes = diskSpace.total || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
let totalSize = 0;
|
||||||
|
let oldestTime = null;
|
||||||
|
let newestTime = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const entries = await fsp.readdir(DEFAULT_BACKUP_DIR);
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (entry.endsWith('.backup')) {
|
||||||
|
const filePath = path.join(DEFAULT_BACKUP_DIR, entry);
|
||||||
|
try {
|
||||||
|
const stats = await fsp.stat(filePath);
|
||||||
|
totalSize += stats.size;
|
||||||
|
result.backupCount++;
|
||||||
|
|
||||||
|
const fileTime = new Date(stats.mtime);
|
||||||
|
if (!oldestTime || fileTime < oldestTime) oldestTime = fileTime;
|
||||||
|
if (!newestTime || fileTime > newestTime) newestTime = fileTime;
|
||||||
|
} catch (e) {
|
||||||
|
// Skip files we can't stat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Backup directory might not exist yet
|
||||||
|
}
|
||||||
|
|
||||||
|
result.usedBytes = totalSize;
|
||||||
|
result.oldestBackup = oldestTime ? oldestTime.toISOString() : null;
|
||||||
|
result.newestBackup = newestTime ? newestTime.toISOString() : null;
|
||||||
|
|
||||||
|
// Calculate available (total limit - used), or from disk space if no limit set
|
||||||
|
if (result.maxStorageBytes > 0) {
|
||||||
|
result.availableBytes = Math.max(0, result.maxStorageBytes - totalSize);
|
||||||
|
result.usagePercent = parseFloat(((totalSize / result.maxStorageBytes) * 100).toFixed(2));
|
||||||
|
} else if (diskSpace.total) {
|
||||||
|
result.availableBytes = diskSpace.available;
|
||||||
|
result.usagePercent = diskSpace.total > 0
|
||||||
|
? parseFloat((((diskSpace.total - diskSpace.available) / diskSpace.total) * 100).toFixed(2))
|
||||||
|
: 0;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[BackupsRouter] Error getting storage info:', error.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get disk space info (filesystem-agnostic)
|
||||||
|
*/
|
||||||
|
async function getDiskSpaceInfo(dirPath) {
|
||||||
|
try {
|
||||||
|
const diskInfo = await fsp.statfs(dirPath);
|
||||||
|
return {
|
||||||
|
total: diskInfo.blocks * diskInfo.bsize,
|
||||||
|
available: diskInfo.bfree * diskInfo.bsize,
|
||||||
|
used: (diskInfo.blocks - diskInfo.bfree) * diskInfo.bsize
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
// Directory might not exist or be accessible
|
||||||
|
return { total: 0, available: 0, used: 0 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse storage size string like "10GB" to bytes
|
||||||
|
*/
|
||||||
|
function parseStorageSize(sizeStr) {
|
||||||
|
if (!sizeStr || typeof sizeStr === 'number') return sizeStr || 0;
|
||||||
|
|
||||||
|
const match = String(sizeStr).match(/^(\d+(?:\.\d+)?)\s*(B|KB|MB|GB|TB|K|M|G|T)?$/i);
|
||||||
|
if (!match) return 0;
|
||||||
|
|
||||||
|
const value = parseFloat(match[1]);
|
||||||
|
const unit = (match[2] || 'B').toUpperCase();
|
||||||
|
|
||||||
|
const multipliers = {
|
||||||
|
'B': 1,
|
||||||
|
'K': 1024,
|
||||||
|
'KB': 1024,
|
||||||
|
'M': 1024 * 1024,
|
||||||
|
'MB': 1024 * 1024,
|
||||||
|
'G': 1024 * 1024 * 1024,
|
||||||
|
'GB': 1024 * 1024 * 1024,
|
||||||
|
'T': 1024 * 1024 * 1024 * 1024,
|
||||||
|
'TB': 1024 * 1024 * 1024 * 1024
|
||||||
|
};
|
||||||
|
|
||||||
|
return Math.floor(value * (multipliers[unit] || 1));
|
||||||
|
}
|
||||||
|
|||||||
@@ -134,11 +134,16 @@ restart_container() {
|
|||||||
# Stop and remove existing container so new env var is applied
|
# Stop and remove existing container so new env var is applied
|
||||||
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
docker rm -f "$CONTAINER_NAME" 2>/dev/null || true
|
||||||
|
|
||||||
# Re-create with same volumes and the SERVICES_FILE env var
|
# Re-create with same volumes. CRITICAL: must include CREDENTIALS_FILE +
|
||||||
|
# ENCRYPTION_KEY_FILE pointing at /app/data/ so the container reads the TOTP
|
||||||
|
# secret from the bind-mounted host data dir (not image-local /app/credentials.json
|
||||||
|
# which gets a fresh encryption key on every container recreate = TOTP breaks).
|
||||||
docker run -d --restart unless-stopped --name "$CONTAINER_NAME" \
|
docker run -d --restart unless-stopped --name "$CONTAINER_NAME" \
|
||||||
-p 127.0.0.1:3001:3001 \
|
-p 127.0.0.1:3001:3001 \
|
||||||
-v /opt/dashcaddy/dashcaddy-api/data:/app/data \
|
-v /opt/dashcaddy/dashcaddy-api/data:/app/data \
|
||||||
-e SERVICES_FILE=/app/data/services.json \
|
-e SERVICES_FILE=/app/data/services.json \
|
||||||
|
-e CREDENTIALS_FILE=/app/d...son \
|
||||||
|
-e ENCRYPTION_KEY_FILE=/app/data/.encryption-key \
|
||||||
"$image"
|
"$image"
|
||||||
log "Container restarted with fresh env"
|
log "Container restarted with fresh env"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,13 @@ let dockerMaintenance, logDigest;
|
|||||||
try { dockerMaintenance = require('../docker-maintenance'); } catch (_) { /* optional module */ }
|
try { dockerMaintenance = require('../docker-maintenance'); } catch (_) { /* optional module */ }
|
||||||
try { logDigest = require('../log-digest'); } catch (_) { /* optional module */ }
|
try { logDigest = require('../log-digest'); } catch (_) { /* optional module */ }
|
||||||
|
|
||||||
|
// Workflow engine (bundled workflows)
|
||||||
|
let bundledWorkflowsModule;
|
||||||
|
let workflowEngine = null;
|
||||||
|
try {
|
||||||
|
bundledWorkflowsModule = require('../bundled-workflows');
|
||||||
|
} catch (_) { /* optional module */ }
|
||||||
|
|
||||||
// Templates
|
// Templates
|
||||||
const { APP_TEMPLATES, TEMPLATE_CATEGORIES, DIFFICULTY_LEVELS } = require('../app-templates');
|
const { APP_TEMPLATES, TEMPLATE_CATEGORIES, DIFFICULTY_LEVELS } = require('../app-templates');
|
||||||
const { RECIPE_TEMPLATES, RECIPE_CATEGORIES } = require('../recipe-templates');
|
const { RECIPE_TEMPLATES, RECIPE_CATEGORIES } = require('../recipe-templates');
|
||||||
@@ -69,6 +76,7 @@ const recipesRoutes = require('../routes/recipes');
|
|||||||
const themesRoutes = require('../routes/themes');
|
const themesRoutes = require('../routes/themes');
|
||||||
const dockerResourcesRoutes = require('../routes/docker-resources');
|
const dockerResourcesRoutes = require('../routes/docker-resources');
|
||||||
const eventsRoutes = require('../routes/events');
|
const eventsRoutes = require('../routes/events');
|
||||||
|
const workflowsRoutes = require('../routes/workflows');
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
const { APP } = require('../constants');
|
const { APP } = require('../constants');
|
||||||
@@ -156,6 +164,21 @@ async function createApp() {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Back-compat: reverse-proxy SSO snippets (Caddy forward_auth + per-service
|
||||||
|
// auto-login pages) historically call these endpoints under the pre-1.5.0
|
||||||
|
// prefix `/api/auth/...`. The canonical mount is `/api/v1`. Hand-maintained
|
||||||
|
// Caddyfiles have repeatedly drifted back to the old prefix and 404'd the SSO
|
||||||
|
// gate (breaking Plex/Jellyfin/Emby/chat). Transparently rewrite ONLY these two
|
||||||
|
// auth paths to the v1 mount so the gate is tolerant of that drift. Must run
|
||||||
|
// before configureMiddleware() so CSRF/auth see the canonical path. This is
|
||||||
|
// deliberately narrow — NOT a general `/api` -> `/api/v1` alias.
|
||||||
|
app.use((req, res, next) => {
|
||||||
|
if (req.url.startsWith('/api/auth/gate/') || req.url.startsWith('/api/auth/app-token/')) {
|
||||||
|
req.url = '/api/v1' + req.url.slice(4); // '/api'.length === 4
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
// Configure middleware
|
// Configure middleware
|
||||||
const middlewareResult = configureMiddleware(app, {
|
const middlewareResult = configureMiddleware(app, {
|
||||||
siteConfig: config.siteConfig,
|
siteConfig: config.siteConfig,
|
||||||
@@ -308,9 +331,55 @@ async function createApp() {
|
|||||||
app,
|
app,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Initialize workflow engine if bundled-workflows is available
|
||||||
|
if (bundledWorkflowsModule && ctx.docker) {
|
||||||
|
try {
|
||||||
|
const { WorkflowEngine } = bundledWorkflowsModule;
|
||||||
|
const workflowCtx = {
|
||||||
|
docker: ctx.docker,
|
||||||
|
notification: ctx.notification,
|
||||||
|
backupManager: ctx.backupManager,
|
||||||
|
resourceMonitor: ctx.resourceMonitor,
|
||||||
|
servicesStateManager: ctx.servicesStateManager
|
||||||
|
};
|
||||||
|
workflowEngine = new WorkflowEngine(workflowCtx);
|
||||||
|
ctx.workflowEngine = workflowEngine;
|
||||||
|
log.info('app', 'Workflow engine initialized');
|
||||||
|
} catch (err) {
|
||||||
|
log.error('app', 'Failed to initialize workflow engine', { error: err.message });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Build versioned API router
|
// Build versioned API router
|
||||||
const apiRouter = express.Router();
|
const apiRouter = express.Router();
|
||||||
|
|
||||||
|
// Wire up notification listeners for resourceMonitor and backupManager
|
||||||
|
if (ctx.notification && ctx.resourceMonitor) {
|
||||||
|
ctx.resourceMonitor.on('alert', (alertData) => {
|
||||||
|
ctx.notification.sendAlert(alertData).catch(err => {
|
||||||
|
log.error('notification', 'Failed to send alert', { error: err.message });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ctx.resourceMonitor.on('auto-restart', (data) => {
|
||||||
|
ctx.notification.sendServiceEvent('auto-restart', data).catch(err => {
|
||||||
|
log.error('notification', 'Failed to send auto-restart notification', { error: err.message });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.notification && ctx.backupManager) {
|
||||||
|
ctx.backupManager.on('backup-complete', (data) => {
|
||||||
|
ctx.notification.send('backup-complete', data).catch(err => {
|
||||||
|
log.error('notification', 'Failed to send backup-complete', { error: err.message });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
ctx.backupManager.on('backup-failed', (data) => {
|
||||||
|
ctx.notification.send('backup-failed', data).catch(err => {
|
||||||
|
log.error('notification', 'Failed to send backup-failed', { error: err.message });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Mount route modules
|
// Mount route modules
|
||||||
apiRouter.use(authRoutes(ctx));
|
apiRouter.use(authRoutes(ctx));
|
||||||
apiRouter.use(configRoutes(ctx));
|
apiRouter.use(configRoutes(ctx));
|
||||||
@@ -330,7 +399,8 @@ async function createApp() {
|
|||||||
apiRouter.use('/containers', containerRoutes({
|
apiRouter.use('/containers', containerRoutes({
|
||||||
docker: ctx.docker,
|
docker: ctx.docker,
|
||||||
log: ctx.log,
|
log: ctx.log,
|
||||||
asyncHandler: ctx.asyncHandler
|
asyncHandler: ctx.asyncHandler,
|
||||||
|
workflowEngine: ctx.workflowEngine
|
||||||
}));
|
}));
|
||||||
apiRouter.use(serviceRoutes({
|
apiRouter.use(serviceRoutes({
|
||||||
servicesStateManager: ctx.servicesStateManager,
|
servicesStateManager: ctx.servicesStateManager,
|
||||||
@@ -361,7 +431,8 @@ async function createApp() {
|
|||||||
resourceMonitor: ctx.resourceMonitor,
|
resourceMonitor: ctx.resourceMonitor,
|
||||||
docker: ctx.docker,
|
docker: ctx.docker,
|
||||||
asyncHandler: ctx.asyncHandler,
|
asyncHandler: ctx.asyncHandler,
|
||||||
log: ctx.log
|
log: ctx.log,
|
||||||
|
notificationManager: ctx.notification
|
||||||
}));
|
}));
|
||||||
apiRouter.use(updatesRoutes({
|
apiRouter.use(updatesRoutes({
|
||||||
updateManager: ctx.updateManager,
|
updateManager: ctx.updateManager,
|
||||||
@@ -404,8 +475,8 @@ async function createApp() {
|
|||||||
}));
|
}));
|
||||||
apiRouter.use(backupsRoutes({
|
apiRouter.use(backupsRoutes({
|
||||||
backupManager: ctx.backupManager,
|
backupManager: ctx.backupManager,
|
||||||
asyncHandler: ctx.asyncHandler,
|
licenseManager: ctx.licenseManager,
|
||||||
licenseManager: ctx.licenseManager
|
asyncHandler: ctx.asyncHandler
|
||||||
}));
|
}));
|
||||||
apiRouter.use('/ca', caRoutes(ctx));
|
apiRouter.use('/ca', caRoutes(ctx));
|
||||||
apiRouter.use(browseRoutes({
|
apiRouter.use(browseRoutes({
|
||||||
@@ -435,6 +506,11 @@ async function createApp() {
|
|||||||
updateManager: ctx.updateManager,
|
updateManager: ctx.updateManager,
|
||||||
logError: ctx.logError
|
logError: ctx.logError
|
||||||
}));
|
}));
|
||||||
|
apiRouter.use(workflowsRoutes({
|
||||||
|
workflowEngine: ctx.workflowEngine,
|
||||||
|
licenseManager: ctx.licenseManager,
|
||||||
|
asyncHandler: ctx.asyncHandler
|
||||||
|
}));
|
||||||
|
|
||||||
// Inline API routes
|
// Inline API routes
|
||||||
apiRouter.get('/health', (req, res) => {
|
apiRouter.get('/health', (req, res) => {
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 6.0 KiB |
@@ -72,6 +72,7 @@ const bundles = {
|
|||||||
],
|
],
|
||||||
'init.js': [
|
'init.js': [
|
||||||
JS('core', 'init.js'),
|
JS('core', 'init.js'),
|
||||||
|
JS('monitoring-widgets.js'),
|
||||||
JS('keyboard-shortcuts.js'),
|
JS('keyboard-shortcuts.js'),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|||||||
Vendored
+114
-87
File diff suppressed because one or more lines are too long
Vendored
+308
-233
File diff suppressed because one or more lines are too long
Vendored
+123
-12
File diff suppressed because one or more lines are too long
Vendored
+3
-3
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
const CACHE = 'dashcaddy-shell-8ef9c82616';
|
const CACHE = 'dashcaddy-shell-594ec75648';
|
||||||
const PRECACHE = [
|
const PRECACHE = [
|
||||||
'/',
|
'/',
|
||||||
'/index.html',
|
'/index.html',
|
||||||
|
|||||||
Reference in New Issue
Block a user