fix(routes): Pass full deps to config/backup and create ctx shim

This commit is contained in:
Krystie
2026-03-30 00:24:47 -07:00
parent a2ee590897
commit ae6f2d9df1
2 changed files with 40 additions and 11 deletions

View File

@@ -5,20 +5,29 @@ const { CADDY } = require('../../constants');
const { exists } = require('../../fs-helpers'); const { exists } = require('../../fs-helpers');
const { ValidationError, AuthenticationError } = require('../../errors'); const { ValidationError, AuthenticationError } = require('../../errors');
module.exports = function({ configStateManager, servicesStateManager, asyncHandler, log }) {
const express = require('express');
/** /**
* Config backup routes factory * Config backup routes factory
* @param {Object} deps - Explicit dependencies * @param {Object} deps - Explicit dependencies
* @param {Object} deps.configStateManager - Config state manager
* @param {Object} deps.servicesStateManager - Services state manager
* @param {Function} deps.asyncHandler - Async route handler wrapper
* @param {Object} deps.log - Logger instance
* @returns {express.Router} * @returns {express.Router}
*/ */
module.exports = function(deps) {
const express = require('express');
const router = express.Router(); const router = express.Router();
const THEMES_DIR = process.env.THEMES_DIR || path.join(path.dirname(ctx.SERVICES_FILE), 'themes'); // Extract dependencies
const {
configStateManager, servicesStateManager, asyncHandler, log,
SERVICES_FILE, CONFIG_FILE, TOTP_CONFIG_FILE, TAILSCALE_CONFIG_FILE, NOTIFICATIONS_FILE,
caddy, dns, fetchT, totpConfig, credentialManager, loadSiteConfig, loadNotificationConfig, session, saveTotpConfig
} = deps;
// Create ctx-like object for compatibility with existing code
const ctx = {
SERVICES_FILE, CONFIG_FILE, TOTP_CONFIG_FILE, TAILSCALE_CONFIG_FILE, NOTIFICATIONS_FILE,
caddy, dns, fetchT, totpConfig, credentialManager, loadSiteConfig, loadNotificationConfig
};
const THEMES_DIR = process.env.THEMES_DIR || path.join(path.dirname(SERVICES_FILE), 'themes');
function readAllThemes() { function readAllThemes() {
const themes = {}; const themes = {};

View File

@@ -8,15 +8,35 @@ const express = require('express');
module.exports = function(ctx) { module.exports = function(ctx) {
const router = express.Router(); const router = express.Router();
const deps = { // Common deps for all config routes
const baseDeps = {
configStateManager: ctx.configStateManager, configStateManager: ctx.configStateManager,
servicesStateManager: ctx.servicesStateManager, servicesStateManager: ctx.servicesStateManager,
asyncHandler: ctx.asyncHandler, asyncHandler: ctx.asyncHandler,
log: ctx.log log: ctx.log
}; };
router.use(require('./settings')(deps)); // Additional deps for backup route
router.use(require('./assets')(deps)); const backupDeps = {
router.use(require('./backup')(deps)); ...baseDeps,
SERVICES_FILE: ctx.SERVICES_FILE,
CONFIG_FILE: ctx.CONFIG_FILE,
TOTP_CONFIG_FILE: ctx.TOTP_CONFIG_FILE,
TAILSCALE_CONFIG_FILE: ctx.TAILSCALE_CONFIG_FILE,
NOTIFICATIONS_FILE: ctx.NOTIFICATIONS_FILE,
caddy: ctx.caddy,
dns: ctx.dns,
fetchT: ctx.fetchT,
totpConfig: ctx.totpConfig,
credentialManager: ctx.credentialManager,
loadSiteConfig: ctx.loadSiteConfig,
loadNotificationConfig: ctx.loadNotificationConfig,
session: ctx.session,
saveTotpConfig: ctx.saveTotpConfig
};
router.use(require('./settings')(baseDeps));
router.use(require('./assets')({ ...baseDeps, CONFIG_FILE: ctx.CONFIG_FILE, readConfig: ctx.readConfig, saveConfig: ctx.saveConfig, errorResponse: ctx.errorResponse }));
router.use(require('./backup')(backupDeps));
return router; return router;
}; };