fix(routes): complete post-refactor dependency wiring cleanup
This commit is contained in:
@@ -17,8 +17,7 @@ const platformPaths = require('../../platform-paths');
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {Object} Helper functions
|
||||
*/
|
||||
module.exports = function(ctx) {
|
||||
const { docker, caddy, credentialManager, servicesStateManager, fetchT, log } = ctx;
|
||||
module.exports = function({ docker, caddy, credentialManager, servicesStateManager, fetchT, log, ctx }) {
|
||||
|
||||
async function checkPortConflicts(ports, excludeContainerName = null) {
|
||||
const conflicts = [];
|
||||
|
||||
@@ -27,17 +27,21 @@ module.exports = function(ctx) {
|
||||
log: ctx.log,
|
||||
// Additional context properties needed by routes
|
||||
APP_TEMPLATES: ctx.APP_TEMPLATES,
|
||||
TEMPLATE_CATEGORIES: ctx.TEMPLATE_CATEGORIES,
|
||||
DIFFICULTY_LEVELS: ctx.DIFFICULTY_LEVELS,
|
||||
siteConfig: ctx.siteConfig,
|
||||
buildDomain: ctx.buildDomain,
|
||||
buildServiceUrl: ctx.buildServiceUrl,
|
||||
addServiceToConfig: ctx.addServiceToConfig,
|
||||
dns: ctx.dns,
|
||||
notification: ctx.notification,
|
||||
safeErrorMessage: ctx.safeErrorMessage
|
||||
safeErrorMessage: ctx.safeErrorMessage,
|
||||
SERVICES_FILE: ctx.SERVICES_FILE,
|
||||
ctx: ctx
|
||||
};
|
||||
|
||||
// Initialize helpers with dependencies
|
||||
const helpers = initHelpers(ctx);
|
||||
// Initialize helpers with dependencies (ctx is the Koa context)
|
||||
const helpers = initHelpers({ ...deps, ctx });
|
||||
|
||||
// Mount sub-routes — pass full ctx so sub-routes can reference ctx.* properties
|
||||
const subCtx = Object.assign({}, ctx, { helpers });
|
||||
|
||||
@@ -1,20 +1,40 @@
|
||||
const express = require('express');
|
||||
const { exists } = require('../../fs-helpers');
|
||||
const { logError } = require('../../src/utils/logging');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
const { docker, caddy, servicesStateManager, asyncHandler, errorResponse, log, helpers } = ctx;
|
||||
module.exports = function({
|
||||
docker, caddy, servicesStateManager, asyncHandler, log, helpers,
|
||||
errorResponse, dns, siteConfig, buildDomain, SERVICES_FILE, safeErrorMessage
|
||||
}) {
|
||||
const router = express.Router();
|
||||
/**
|
||||
* Apps removal routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Object} deps.docker - Docker client wrapper
|
||||
* @param {Object} deps.caddy - Caddy client
|
||||
* @param {Object} deps.servicesStateManager - Services state manager
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @param {Object} deps.helpers - Apps helpers module
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
|
||||
// Ctx shim for backward compatibility with existing route code
|
||||
const ctx = {
|
||||
dns,
|
||||
siteConfig,
|
||||
buildDomain,
|
||||
SERVICES_FILE,
|
||||
safeErrorMessage
|
||||
};
|
||||
|
||||
// Remove deployed app
|
||||
/**
|
||||
* Apps removal routes factory
|
||||
* @param {Object} deps - Explicit dependencies
|
||||
* @param {Object} deps.docker - Docker client wrapper
|
||||
* @param {Object} deps.caddy - Caddy client
|
||||
* @param {Object} deps.servicesStateManager - Services state manager
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @param {Object} deps.helpers - Apps helpers module
|
||||
* @param {Function} deps.errorResponse - Error response helper
|
||||
* @param {Object} deps.dns - DNS context
|
||||
* @param {Object} deps.siteConfig - Site configuration
|
||||
* @param {Function} deps.buildDomain - Build domain helper
|
||||
* @param {string} deps.SERVICES_FILE - Services file path
|
||||
* @param {Function} deps.safeErrorMessage - Safe error message formatter
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
router.delete('/apps/:appId', asyncHandler(async (req, res) => {
|
||||
const { appId } = req.params;
|
||||
const { containerId, subdomain, ip, deleteContainer } = req.query;
|
||||
|
||||
@@ -8,14 +8,23 @@ const { DOCKER } = require('../../constants');
|
||||
* @param {Object} deps.caddy - Caddy client
|
||||
* @param {Object} deps.servicesStateManager - Services state manager
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Function} deps.errorResponse - Error response helper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @param {Object} deps.helpers - Apps helpers module
|
||||
* @param {Object} deps.APP_TEMPLATES - App templates registry
|
||||
* @param {Object} deps.dns - DNS client
|
||||
* @param {Function} deps.buildServiceUrl - Service URL builder
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function(ctx) {
|
||||
const { docker, caddy, servicesStateManager, asyncHandler, log, helpers } = ctx;
|
||||
module.exports = function({ docker, caddy, servicesStateManager, asyncHandler, errorResponse, log, helpers, APP_TEMPLATES, dns, buildServiceUrl }) {
|
||||
const router = express.Router();
|
||||
|
||||
const ctx = {
|
||||
APP_TEMPLATES,
|
||||
dns,
|
||||
buildServiceUrl
|
||||
};
|
||||
|
||||
/**
|
||||
* Restore a single service from its deployment manifest.
|
||||
* Pulls image, creates container, starts it, recreates Caddy config.
|
||||
@@ -125,11 +134,6 @@ module.exports = function(ctx) {
|
||||
// Static sites: just recreate Caddy config
|
||||
if (template?.isStaticSite) {
|
||||
log.info('restore', `Restoring static site Caddy config: ${service.name}`);
|
||||
const caddyOptions = {
|
||||
tailscaleOnly: manifest.caddy.tailscaleOnly,
|
||||
allowedIPs: manifest.caddy.allowedIPs,
|
||||
subpathSupport: manifest.caddy.subpathSupport,
|
||||
};
|
||||
// Static site Caddy config would need to be regenerated
|
||||
// For now, just confirm the service entry exists
|
||||
return {
|
||||
@@ -288,7 +292,7 @@ module.exports = function(ctx) {
|
||||
const svc = services.find(s => s.id === service.id);
|
||||
if (svc) {
|
||||
svc.containerId = container.id;
|
||||
svc.url = ctx.buildServiceUrl(manifest.config.subdomain);
|
||||
svc.url = buildServiceUrl(manifest.config.subdomain);
|
||||
}
|
||||
return services;
|
||||
});
|
||||
|
||||
@@ -6,14 +6,40 @@ const { exists } = require('../../fs-helpers');
|
||||
* @param {Object} deps.servicesStateManager - Services state manager
|
||||
* @param {Function} deps.asyncHandler - Async route handler wrapper
|
||||
* @param {Object} deps.helpers - Apps helpers module
|
||||
* @param {Object} deps.APP_TEMPLATES - App templates registry
|
||||
* @param {Object} deps.TEMPLATE_CATEGORIES - Template categories
|
||||
* @param {Object} deps.DIFFICULTY_LEVELS - Difficulty levels
|
||||
* @param {Object} deps.docker - Docker client
|
||||
* @param {Object} deps.caddy - Caddy client
|
||||
* @param {Object} deps.dns - DNS context
|
||||
* @param {Object} deps.siteConfig - Site configuration
|
||||
* @param {Function} deps.buildDomain - Build domain helper
|
||||
* @param {Function} deps.errorResponse - Error response helper
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @param {string} deps.SERVICES_FILE - Services file path
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
const { REGEX } = require('../../constants');
|
||||
|
||||
module.exports = function(ctx) {
|
||||
const { servicesStateManager, asyncHandler, helpers, docker, caddy, log, errorResponse } = ctx;
|
||||
module.exports = function({
|
||||
servicesStateManager, asyncHandler, helpers,
|
||||
APP_TEMPLATES, TEMPLATE_CATEGORIES, DIFFICULTY_LEVELS,
|
||||
docker, caddy, dns, siteConfig, buildDomain,
|
||||
errorResponse, log, SERVICES_FILE
|
||||
}) {
|
||||
const router = express.Router();
|
||||
|
||||
// Ctx shim for backward compatibility with existing route code
|
||||
const ctx = {
|
||||
APP_TEMPLATES,
|
||||
TEMPLATE_CATEGORIES,
|
||||
DIFFICULTY_LEVELS,
|
||||
dns,
|
||||
siteConfig,
|
||||
buildDomain,
|
||||
SERVICES_FILE
|
||||
};
|
||||
|
||||
// Get available app templates
|
||||
router.get('/apps/templates', asyncHandler(async (req, res) => {
|
||||
res.json({
|
||||
@@ -64,6 +90,8 @@ module.exports = function(ctx) {
|
||||
// Update subdomain for deployed app
|
||||
router.post('/apps/update-subdomain', asyncHandler(async (req, res) => {
|
||||
const { serviceId, oldSubdomain, newSubdomain, containerId, ip } = req.body;
|
||||
const { ValidationError } = require('../../errors');
|
||||
|
||||
if (!oldSubdomain || typeof oldSubdomain !== 'string') {
|
||||
throw new ValidationError('oldSubdomain is required');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user