feat(health): pure helper to pick local/remote service URLs
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
28
public/views/service_url.js
Normal file
28
public/views/service_url.js
Normal file
@@ -0,0 +1,28 @@
|
||||
// Pure helpers: choose which URL a service tile opens, based on whether the dashboard
|
||||
// is being viewed on-network (LAN) or remotely. No DOM / no network access here.
|
||||
|
||||
const PRIVATE_RE = /^(localhost$|127\.|10\.|192\.168\.|172\.(1[6-9]|2\d|3[01])\.)/;
|
||||
|
||||
// True when `hostname` is NOT a private/local address — i.e. the dashboard is being
|
||||
// accessed remotely (e.g. via void.hynesy.com).
|
||||
export function isRemoteHost(hostname = '') {
|
||||
const h = String(hostname).toLowerCase();
|
||||
if (!h) return false;
|
||||
if (PRIVATE_RE.test(h)) return false;
|
||||
if (h.endsWith('.local') || h.endsWith('.lan')) return false;
|
||||
if (!h.includes('.')) return false; // bare hostname (e.g. "ct311")
|
||||
return true;
|
||||
}
|
||||
|
||||
// For a service ({ url, external }) and whether we're remote, return the primary URL
|
||||
// the tile opens, an optional alt (the other URL) for one-click fallback, and whether
|
||||
// the service is LAN-only while remote.
|
||||
export function pickServiceUrls(svc = {}, remote = false) {
|
||||
const url = svc.url || '';
|
||||
const external = svc.external || '';
|
||||
let primary, alt;
|
||||
if (remote) { primary = external || url; alt = external ? url : ''; }
|
||||
else { primary = url; alt = external || ''; }
|
||||
if (alt && alt === primary) alt = '';
|
||||
return { primary, alt: alt || null, lanOnly: remote && !external };
|
||||
}
|
||||
Reference in New Issue
Block a user