Unify URL resolution, add health checker sync, and make modules optional

- Add url-resolver.js with single resolveServiceUrl() used by all 5 consumers
  (probes, health routes, health checker auto-config)
- Health checker now does full sync (add/update/remove) instead of add-only,
  and re-syncs automatically after every services.json mutation
- docker-maintenance and log-digest are now optional imports with try/catch,
  preventing container crashes when these files are absent
- Add null guards in routes/logs.js for graceful 503 responses

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-14 23:01:20 -07:00
parent 70b818c2bd
commit 2815233e86
7 changed files with 145 additions and 106 deletions

View File

@@ -6,6 +6,7 @@ const { TIMEOUTS } = require('../constants');
const { exists } = require('../fs-helpers');
const { paginate, parsePaginationParams } = require('../pagination');
const platformPaths = require('../platform-paths');
const { resolveServiceUrl } = require('../url-resolver');
module.exports = function(ctx) {
const router = express.Router();
@@ -36,18 +37,7 @@ module.exports = function(ctx) {
let checkType = 'http';
// Determine URL to check
if (service.isExternal && service.externalUrl) {
url = service.externalUrl;
} else if (service.containerId || service.containerName) {
// Local container - check via localhost and port
const port = service.port || 80;
url = `http://localhost:${port}`;
} else if (service.url) {
url = service.url.startsWith('http') ? service.url : `https://${service.url}`;
} else if (service.id) {
// Try common URL pattern
url = `https://${ctx.buildDomain(service.id)}`;
}
url = resolveServiceUrl(serviceId, service, ctx.siteConfig, ctx.buildServiceUrl);
if (!url) {
health[serviceId] = { status: 'unknown', reason: 'No URL configured' };
@@ -157,14 +147,7 @@ module.exports = function(ctx) {
}
// Determine URL
let url = null;
if (service.isExternal && service.externalUrl) {
url = service.externalUrl;
} else if (service.url) {
url = service.url.startsWith('http') ? service.url : `https://${service.url}`;
} else {
url = `https://${ctx.buildDomain(serviceId)}`;
}
const url = resolveServiceUrl(serviceId, service, ctx.siteConfig, ctx.buildServiceUrl);
// Check health
const controller = new AbortController();