Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring
TypeScript diagramhomelabhomelab-infrastructure-observabilitynetworkproxmox-veself-hostedzigbeezwavezwave-js
fix(services): stop appending the scanned port to a custom service host
Pouzor28f3ac38781c
diff --git a/backend/app/services/status_checker.py b/backend/app/services/status_checker.pyindex 45da3fd..21dbab1 100644--- a/backend/app/services/status_checker.py+++ b/backend/app/services/status_checker.py@@ -219,7 +219,11 @@ async def check_service(svc: dict[str, Any], host: str | None) -> str:port in _HTTPS_PORTS or "https" in name or "ssl" in name or "tls" in name) else "http")url_host = _service_host(svc, host)- url = f"{scheme}://{url_host}" + (f":{port}" if port is not None else "")+ # A host override usually points at a reverse proxy, where the scanned+ # port is an internal detail that would break the public URL. Only a+ # port typed into the override itself is used.+ url_port = override_port if override else port+ url = f"{scheme}://{url_host}" + (f":{url_port}" if url_port is not None else "")return "online" if await _http_get(url, verify=False) else "offline"except Exception as exc:logger.debug("Service check failed for %s:%s (%s)", host, port, exc)diff --git a/backend/tests/test_status_checker.py b/backend/tests/test_status_checker.pyindex c26c10f..42a3724 100644--- a/backend/tests/test_status_checker.py+++ b/backend/tests/test_status_checker.py@@ -516,7 +516,14 @@ async def _captured_url(svc, host):@pytest.mark.asyncioasync def test_check_service_uses_the_host_override():svc = {"port": 8080, "protocol": "tcp", "service_name": "blog", "host": "blog.example.com"}- assert await _captured_url(svc, "10.0.0.1") == "http://blog.example.com:8080"+ assert await _captured_url(svc, "10.0.0.1") == "http://blog.example.com"+++async def test_check_service_drops_the_scanned_port_behind_a_reverse_proxy():+ """Issue #382 — an override points at a proxy; the internal port breaks it."""+ svc = {"port": 8083, "protocol": "tcp", "service_name": "blog", "host": "https://mywebserver.mydomain.com"}+ assert await _captured_url(svc, "192.168.100.100") == "https://mywebserver.mydomain.com"@pytest.mark.asyncio@@ -538,21 +545,21 @@ async def test_check_service_takes_the_port_from_the_override():@pytest.mark.asyncio-async def test_check_service_lets_the_service_port_beat_the_override_port():+async def test_check_service_keeps_the_port_typed_into_the_override():svc = {"port": 3000, "protocol": "tcp", "service_name": "blog", "host": "blog.example.com:8443"}- assert await _captured_url(svc, "10.0.0.1") == "http://blog.example.com:3000"+ assert await _captured_url(svc, "10.0.0.1") == "http://blog.example.com:8443"@pytest.mark.asyncioasync def test_check_service_uses_the_first_host_of_a_comma_list_override():svc = {"port": 8080, "protocol": "tcp", "service_name": "blog", "host": "blog.example.com, alt.example.com"}- assert await _captured_url(svc, "10.0.0.1") == "http://blog.example.com:8080"+ assert await _captured_url(svc, "10.0.0.1") == "http://blog.example.com"@pytest.mark.asyncioasync def test_check_service_brackets_an_ipv6_override():svc = {"port": 80, "protocol": "tcp", "service_name": "http", "host": "[2001:db8::1]:8080"}- assert await _captured_url(svc, "10.0.0.1") == "http://[2001:db8::1]:80"+ assert await _captured_url(svc, "10.0.0.1") == "http://[2001:db8::1]:8080"@pytest.mark.asynciodiff --git a/frontend/src/components/modals/ServiceModal.tsx b/frontend/src/components/modals/ServiceModal.tsxindex 1ad3641..6a96154 100644--- a/frontend/src/components/modals/ServiceModal.tsx+++ b/frontend/src/components/modals/ServiceModal.tsx@@ -146,7 +146,8 @@ export function ServiceModal({ open, onClose, onSubmit, initial, title = 'Add SeclassName="bg-[#21262d] border-[#30363d] font-mono text-sm h-8"/><span className="text-[10px] text-muted-foreground/60">- Overrides the node host for this service only.+ Overrides the node host for this service only. The port above is+ dropped — add one here (host:port) if the URL needs it.</span></div>diff --git a/frontend/src/components/panels/__tests__/DetailPanel.test.tsx b/frontend/src/components/panels/__tests__/DetailPanel.test.tsxindex f0e63c1..74a1616 100644--- a/frontend/src/components/panels/__tests__/DetailPanel.test.tsx+++ b/frontend/src/components/panels/__tests__/DetailPanel.test.tsx@@ -482,7 +482,7 @@ describe('DetailPanel', () => {ungroup: vi.fn(),} as unknown as ReturnType<typeof canvasStore.useCanvasStore>)render(<DetailPanel onEdit={vi.fn()} />)- expect(screen.getByRole('link', { name: 'blog' }).getAttribute('href')).toBe('https://blog.example.com:443')+ expect(screen.getByRole('link', { name: 'blog' }).getAttribute('href')).toBe('https://blog.example.com')})it('calls updateNode without the removed service when X is clicked', () => {diff --git a/frontend/src/types/index.ts b/frontend/src/types/index.tsindex 808dca1..19d4bad 100644--- a/frontend/src/types/index.ts+++ b/frontend/src/types/index.ts@@ -95,7 +95,9 @@ export interface ServiceInfo {category?: string/** Overrides the node host when building the service URL — one node can serve* several domains. Same accepted shapes as a node `ip`/`hostname`- * (`host`, `host:port`, `https://host/…`). */+ * (`host`, `host:port`, `https://host/…`). An override suppresses `port`:+ * it usually names a reverse proxy, where the scanned port breaks the URL,+ * so only a port written here is used. */host?: string/** Whether the node drawing this device shows the service. Per node, not per* device — the same device on another canvas keeps its own answer. Absentdiff --git a/frontend/src/utils/__tests__/serviceUrl.test.ts b/frontend/src/utils/__tests__/serviceUrl.test.tsindex 0392b58..f8fc075 100644--- a/frontend/src/utils/__tests__/serviceUrl.test.ts+++ b/frontend/src/utils/__tests__/serviceUrl.test.ts@@ -86,7 +86,11 @@ describe('getServiceUrl', () => {({ ...svc(port, 'tcp', 'app', path), host })it('uses the service host instead of the node one', () => {- expect(getServiceUrl(withHost('blog.example.com', 8080), '192.168.1.10')).toBe('http://blog.example.com:8080')+ expect(getServiceUrl(withHost('blog.example.com', 8080), '192.168.1.10')).toBe('http://blog.example.com')+ })++ it('drops the scanned port so a reverse-proxy host stays reachable', () => {+ expect(getServiceUrl(withHost('https://mywebserver.mydomain.com', 8083), '192.168.100.100')).toBe('https://mywebserver.mydomain.com')})it('falls back to the node host when the override is blank', () => {@@ -94,7 +98,7 @@ describe('getServiceUrl', () => {})it('resolves against the override even when the node has no host', () => {- expect(getServiceUrl(withHost('blog.example.com', 80), undefined)).toBe('http://blog.example.com:80')+ expect(getServiceUrl(withHost('blog.example.com', 80), undefined)).toBe('http://blog.example.com')})it('honours a scheme carried by the override', () => {@@ -106,15 +110,20 @@ describe('getServiceUrl', () => {})it('appends the service path to the override host', () => {- expect(getServiceUrl(withHost('blog.example.com', 3000, 'admin'), '192.168.1.10')).toBe('http://blog.example.com:3000/admin')+ expect(getServiceUrl(withHost('blog.example.com', 3000, 'admin'), '192.168.1.10')).toBe('http://blog.example.com/admin')})it('returns null for a scheme-only override instead of throwing', () => {expect(getServiceUrl(withHost('https://', 443), '192.168.1.10')).toBeNull()})- it('lets the service port override the port carried by the override host', () => {- expect(getServiceUrl(withHost('blog.example.com:8443', 3000), '192.168.1.10')).toBe('http://blog.example.com:3000')+ it('keeps the port typed into the override host over the scanned one', () => {+ expect(getServiceUrl(withHost('blog.example.com:8443', 3000), '192.168.1.10')).toBe('http://blog.example.com:8443')+ })++ it('still gates the override on the scanned port', () => {+ expect(getServiceUrl(withHost('db.example.com', 3306), '192.168.1.10')).toBeNull()+ expect(getServiceUrl(withHost('shell.example.com', 22), '192.168.1.10')).toBeNull()})it('still returns null for a UDP service', () => {diff --git a/frontend/src/utils/serviceUrl.ts b/frontend/src/utils/serviceUrl.tsindex cff2f90..9063b0e 100644--- a/frontend/src/utils/serviceUrl.ts+++ b/frontend/src/utils/serviceUrl.ts@@ -88,7 +88,8 @@ function formatHostname(hostname: string): string {export function getServiceUrl(svc: ServiceInfo, host?: string): string | null {// A node can serve several domains, so a service may carry its own host that// overrides the node one.- const effectiveHost = svc.host?.trim() || host+ const overrideHost = svc.host?.trim()+ const effectiveHost = overrideHost || hostif (!effectiveHost) return nullif (svc.protocol === 'udp') return null // UDP — not HTTP@@ -106,7 +107,12 @@ export function getServiceUrl(svc: ServiceInfo, host?: string): string | null {? 'https': 'http')+ // A host override usually points at a reverse proxy, where the scanned port+ // is an internal detail that would break the public URL. Only a port typed+ // into the override itself is printed.+ const urlPort = overrideHost ? parts.port : effectivePort+const base = `${protocol}://${formatHostname(parts.hostname)}`- const port = effectivePort != null ? `:${effectivePort}` : ''+ const port = urlPort != null ? `:${urlPort}` : ''return `${base}${port}${normalizePath(svc.path)}`}