Files
dashcaddy/dashcaddy-api/routes/apps/index.js
Sami f865790fe1 fix(routes): restore ctx access in 15 route files broken by Phase 2.1 refactor
The modular refactor changed function signatures to destructured deps but
left internal ctx.* references intact, causing "ctx is not defined" errors
on /api/config, /api/logo, and many other endpoints. Also implements
loadTotpConfig and saveTotpConfig which were left as stubs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-30 03:01:29 -07:00

50 lines
1.5 KiB
JavaScript

const express = require('express');
const initHelpers = require('./helpers');
const initDeploy = require('./deploy');
const initRemoval = require('./removal');
const initTemplates = require('./templates');
const initRestore = require('./restore');
/**
* Apps routes aggregator
* Assembles all apps sub-routes with their dependencies
* @param {Object} ctx - Application context (for backward compatibility)
* @returns {express.Router}
*/
module.exports = function(ctx) {
const router = express.Router();
// Extract dependencies from context
const deps = {
docker: ctx.docker,
caddy: ctx.caddy,
credentialManager: ctx.credentialManager,
servicesStateManager: ctx.servicesStateManager,
portLockManager: ctx.portLockManager,
asyncHandler: ctx.asyncHandler,
errorResponse: ctx.errorResponse,
log: ctx.log,
// Additional context properties needed by routes
APP_TEMPLATES: ctx.APP_TEMPLATES,
siteConfig: ctx.siteConfig,
buildDomain: ctx.buildDomain,
buildServiceUrl: ctx.buildServiceUrl,
addServiceToConfig: ctx.addServiceToConfig,
dns: ctx.dns,
notification: ctx.notification,
safeErrorMessage: ctx.safeErrorMessage
};
// Initialize helpers with dependencies
const helpers = initHelpers(ctx);
// Mount sub-routes — pass full ctx so sub-routes can reference ctx.* properties
const subCtx = Object.assign({}, ctx, { helpers });
router.use(initDeploy(subCtx));
router.use(initRemoval(subCtx));
router.use(initTemplates(subCtx));
router.use(initRestore(subCtx));
return router;
};