Enhance health check functionality to support service ID lookup; update healthcheck endpoint and services-loader.js for improved service card creation

This commit is contained in:
MayaChat
2025-11-24 12:36:32 -05:00
parent 423557fe5c
commit 97ba8cc3ce
2 changed files with 45 additions and 5 deletions

View File

@@ -82,6 +82,7 @@
// Function to create a service card
function createServiceCard(s, host, allServices, tailscaleIP) {
const name = s.getAttribute('name') || s.getAttribute('id') || 'unknown';
const serviceId = s.getAttribute('id') || name.toLowerCase().replace(/\s+/g, '-');
const proto = s.getAttribute('proto') || 'http';
const port = s.getAttribute('port') || '';
const logo = s.getAttribute('logo') || '';
@@ -122,9 +123,7 @@
}
}
// Always proxy health checks via same-origin endpoint to avoid mixed-content
const encodedHost = encodeURIComponent(parsedHost);
const hcPort = parsedPort || (pageIsSecure ? '443' : (parsedProto === 'https' ? '443' : '80'));
healthCheckUrl = `/healthcheck?host=${encodedHost}&port=${encodeURIComponent(hcPort)}&proto=${encodeURIComponent(parsedProto)}`;
healthCheckUrl = `/healthcheck?id=${encodeURIComponent(serviceId)}`;
} else {
// Local service - use Tailscale IP if configured, otherwise current hostname
const targetHost = localIpAttr || tailscaleIP || host;
@@ -141,7 +140,7 @@
} else if(tailscaleIP){
console.log(`Service ${name}: using tailscale-ip ${tailscaleIP} for proxied health checks`);
}
healthCheckUrl = `/healthcheck?host=${encodedHost}&port=${encodeURIComponent(hcPort)}&proto=${encodeURIComponent(desiredProto)}`;
healthCheckUrl = `/healthcheck?id=${encodeURIComponent(serviceId)}`;
// Warn when site is secure but service link is HTTP and target is a private IP
if(pageIsSecure && proto === 'http' && targetHost === tailscaleIP){
console.warn(`Service ${name} will use HTTP at ${href}, but the page is loaded over HTTPS — mixed-content checks will prevent programmatic health checks to the service. Consider enabling TLS or providing a public hostname.`);