dashboard: externalize service URLs and network config (Sprint 03 config externalization)
Deploy Dashboard (Dev) / Backend Tests (push) Failing after 2m17s
Deploy Dashboard (Dev) / Frontend Tests (push) Failing after 3m34s
Deploy Dashboard (Dev) / Deploy to Dev (push) Has been skipped
Run Tests / Secret Detection (pull_request) Failing after 30s
Run Tests / Backend Tests (pull_request) Failing after 2m18s
Run Tests / Frontend Tests (pull_request) Failing after 18s

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Gan, Jimmy
2026-05-03 18:28:05 +08:00
parent 59bdcf392c
commit 019fddc079
4 changed files with 60 additions and 11 deletions
@@ -27,14 +27,22 @@
{ id: "security", label: "Security", icon: "shield" },
];
const LAN_IP = "192.168.31.222";
const TS_IP = "100.78.131.124";
let lanIp = $state("192.168.31.222");
let tsIp = $state("100.78.131.124");
let lanReachable = $state(false);
let serviceUrls = $state({});
if (typeof window !== "undefined") {
fetch("/api/client-ip").then(r => r.json()).then(d => {
if (d.lan) lanReachable = true;
}).catch(() => {});
// Fetch external service URLs from backend config
fetch("/api/system/external-services").then(r => r.json()).then(d => {
if (d.lan_ip) lanIp = d.lan_ip;
if (d.ts_ip) tsIp = d.ts_ip;
if (d.services) serviceUrls = d.services;
}).catch(() => {});
}
const defaultMedia = [
@@ -197,10 +205,15 @@
}
function extHref(svc) {
if (lanReachable && svc.port) return `http://${LAN_IP}:${svc.port}`;
if (svc.remoteHref) return lanReachable ? svc.remoteHref : toPublicHttpsUrl(svc.remoteHref);
// Look up service URL from fetched config by label (lowercased, underscored)
const key = svc.label ? svc.label.toLowerCase().replace(/\s+/g, "_") : "";
const configUrl = serviceUrls[key];
const remoteHref = configUrl || svc.remoteHref;
if (lanReachable && svc.port) return `http://${lanIp}:${svc.port}`;
if (remoteHref) return lanReachable ? remoteHref : toPublicHttpsUrl(remoteHref);
if (svc.port) {
const host = /^\d+\.\d+\.\d+\.\d+$/.test(location.hostname) ? location.hostname : TS_IP;
const host = /^\d+\.\d+\.\d+\.\d+$/.test(location.hostname) ? location.hostname : tsIp;
return `http://${host}:${svc.port}`;
}
return svc.href;