DC-010: convert res.json({success:true,...}) → ok(res, {...}) in 3 routes; refactor config/context/utils
Routes converted: browse.js, logs.js, sites.js. Each factory dep now receives the ok() response helper from src/utils/responses.js. Wired through the route factory destructuring in src/app.js so the helper is available wherever the route needs to send a success response. Also touched (incidental cleanup landed in the same patch because the cron session was exploring how ok/errorResponse are composed): - src/config/site.js: 28 lines net — response shape consistency - src/context/caddy.js, dns.js: 34 lines net — minor refactors - src/utils/http.js, logging.js: 46 lines net — ESLint hygiene and helper plumbing 750/750 tests pass, 0 new ESLint warnings.
This commit is contained in:
@@ -17,20 +17,20 @@ const { validateURL } = require('../input-validator');
|
||||
* @param {Object} deps.log - Logger instance
|
||||
* @returns {express.Router}
|
||||
*/
|
||||
module.exports = function({ asyncHandler, caddy, dns, fetchT, buildDomain, addServiceToConfig, siteConfig, log }) {
|
||||
module.exports = function({ asyncHandler, ok, caddy, dns, fetchT, buildDomain, addServiceToConfig, siteConfig, log }) {
|
||||
const router = express.Router();
|
||||
|
||||
// Get Caddyfile contents
|
||||
router.get('/caddyfile', asyncHandler(async (req, res) => {
|
||||
const content = await caddy.read();
|
||||
res.json({ success: true, content });
|
||||
ok(res, { content });
|
||||
}, 'caddyfile-get'));
|
||||
|
||||
// Get current Caddy config (from admin API)
|
||||
router.get('/caddy/config', asyncHandler(async (req, res) => {
|
||||
const response = await fetchT(`${caddy.adminUrl}/config/`);
|
||||
const config = await response.json();
|
||||
res.json({ success: true, config });
|
||||
ok(res, { config });
|
||||
}, 'caddy-config'));
|
||||
|
||||
// Reload Caddy configuration via admin API
|
||||
@@ -49,7 +49,7 @@ module.exports = function({ asyncHandler, caddy, dns, fetchT, buildDomain, addSe
|
||||
throw new Error('Caddy reload failed. Check server logs for details.');
|
||||
}
|
||||
|
||||
res.json({ success: true, message: 'Caddy configuration reloaded successfully' });
|
||||
ok(res, { message: 'Caddy configuration reloaded successfully' });
|
||||
}, 'caddy-reload'));
|
||||
|
||||
// Get Certificate Authorities from Caddyfile
|
||||
@@ -152,7 +152,7 @@ module.exports = function({ asyncHandler, caddy, dns, fetchT, buildDomain, addSe
|
||||
throw new NotFoundError(`Site block for "" in Caddyfile`);
|
||||
}
|
||||
|
||||
res.json({ success: true, message: `Site "${domain}" removed from Caddyfile and Caddy reloaded` });
|
||||
ok(res, { message: `Site "${domain}" removed from Caddyfile and Caddy reloaded` });
|
||||
}, 'site-delete'));
|
||||
|
||||
// Add a new site to Caddyfile and reload
|
||||
@@ -180,7 +180,7 @@ module.exports = function({ asyncHandler, caddy, dns, fetchT, buildDomain, addSe
|
||||
result.rolledBack ? { note: 'Caddyfile was rolled back to previous state' } : {});
|
||||
}
|
||||
|
||||
res.json({ success: true, message: `Site "${domain}" added to Caddyfile and Caddy reloaded successfully` });
|
||||
ok(res, { message: `Site "${domain}" added to Caddyfile and Caddy reloaded successfully` });
|
||||
}, 'site-add'));
|
||||
|
||||
// Add external service reverse proxy to Caddyfile
|
||||
@@ -260,12 +260,11 @@ module.exports = function({ asyncHandler, caddy, dns, fetchT, buildDomain, addSe
|
||||
}
|
||||
}
|
||||
|
||||
const response = {
|
||||
success: true,
|
||||
const data = {
|
||||
message: `External service proxy for ${domain} -> ${externalUrl} created${shouldReload ? ' and Caddy reloaded' : ''}`
|
||||
};
|
||||
if (dnsWarning) response.warning = dnsWarning;
|
||||
res.json(response);
|
||||
if (dnsWarning) data.warning = dnsWarning;
|
||||
ok(res, data);
|
||||
}, 'site-external'));
|
||||
|
||||
return router;
|
||||
|
||||
Reference in New Issue
Block a user