refactor: update dashboard routing logic, improve sync status handling, and enhance UI layout in health-server.js
Browse files8 unmodified lines910111213141515 unmodified lines31323334353637383940414243444512 unmodified lines585960616263646566676869707172 unmodified lines1441451461471481491505 unmodified lines156157158159160161162171 unmodified lines334335336337338339146 unmodified lines48648748848949049124 unmodified lines51651751851952052152252352452552652752852953053153253378 unmodified lines612613614615616617618267 unmodified lines88688788888989089189265 unmodified lines95895996096196296396453 unmodified lines1018101910201021102210231024102510 unmodified lines103610371038103910401041104210438 unmodified linesconst GATEWAY_HOST = "127.0.0.1";const startTime = Date.now();const LLM_MODEL = process.env.LLM_MODEL || "Not Set";const SPACE_HOST = process.env.SPACE_HOST || "";const TELEGRAM_ENABLED = !!process.env.TELEGRAM_BOT_TOKEN;const WHATSAPP_ENABLED = /^true$/i.test(process.env.WHATSAPP_ENABLED || "");const WHATSAPP_STATUS_FILE = "/tmp/huggingclaw-wa-status.json";15 unmodified lines}function isDashboardRoute(pathname) {return pathname === "/" || pathname === DASHBOARD_BASE || pathname === `${DASHBOARD_BASE}/`;}function isDashboardScopedPath(pathname, suffix) {return pathname === `${DASHBOARD_BASE}/${suffix}`;}function isDashboardAppRoute(pathname) {return pathname === DASHBOARD_APP_BASE || pathname.startsWith(`${DASHBOARD_APP_BASE}/`);}function isAppRoute(pathname) {12 unmodified lines);}function stripDashboardAppPrefix(path) {if (path === DASHBOARD_APP_BASE) return "/";if (path.startsWith(`${DASHBOARD_APP_BASE}/`)) {return path.slice(DASHBOARD_APP_BASE.length) || "/";}if (path === APP_BASE) return "/";if (path.startsWith(`${APP_BASE}/`)) {return path.slice(APP_BASE.length) || "/";}return path;}72 unmodified lineslet badgeClass = "status-offline";let pulseHtml = "";if (syncData.status === "success") {badgeClass = "status-online";pulseHtml = '<div class="pulse"></div>';} else if (syncData.status === "syncing") {5 unmodified lines}function renderDashboard(initialData) {const controlUiHref = `${DASHBOARD_APP_BASE}/`;return `<!DOCTYPE html><html lang="en">171 unmodified lines#sync-msg { color: var(--text); display: block; margin-top: 4px; }.helper-card {width: 100%;margin-top: 20px;146 unmodified linespadding: 16px;}.helper-row {flex-direction: column;}24 unmodified lines</div><div class="stat-card"><span class="stat-label">WhatsApp</span><span id="wa-status">${renderChannelBadge(initialData.whatsapp, 'Ready to pair')}</span></div><div class="stat-card"><span class="stat-label">Telegram</span><span id="tg-status">${renderChannelBadge(initialData.telegram, 'Configured')}</span></div><a href="${controlUiHref}" id="control-ui-link" class="stat-btn">Open Control UI</a></div><div class="stat-card" style="width: 100%;"><span class="stat-label">Workspace Sync Status</span><div id="sync-badge-container">${renderSyncBadge(initialData.sync)}</div><div class="sync-info">Last Sync Activity: <span id="sync-time">${initialData.sync.timestamp || "Never"}</span><span id="sync-msg">${initialData.sync.message || "Waiting for first sync..."}</span>78 unmodified lineslet badgeClass = 'status-offline';let pulseHtml = '';if (syncData.status === 'success') {badgeClass = 'status-online';pulseHtml = '<div class="pulse"></div>';} else if (syncData.status === 'syncing') {267 unmodified linesreturn forwardedHeaders;}function proxyUpgrade(req, socket, head, proxyPath = req.url, proxyPort = GATEWAY_PORT) {const proxySocket = net.connect(proxyPort, GATEWAY_HOST);proxySocket.on("connect", () => {65 unmodified linesreturn;}if (pathname === "/uptimerobot/setup" || pathname === DASHBOARD_UPTIMEROBOT_PATH) {if (req.method !== "POST") {res.writeHead(405, { "Content-Type": "application/json" });res.end(JSON.stringify({ message: "Method not allowed" }));53 unmodified lines}if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {const proxyPath =stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");proxyHttp(req, res, proxyPath, GATEWAY_PORT);return;}10 unmodified linesif (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {const parsedUrl = parseRequestUrl(req.url || "/");const proxyPath =stripDashboardAppPrefix(pathname) + (parsedUrl.search || "");proxyUpgrade(req, socket, head, proxyPath, GATEWAY_PORT);return;}8 unmodified lines9101112131415 unmodified lines30313233343536373839404142434445464712 unmodified lines6061626364656667686970717272 unmodified lines1451461471481491501515 unmodified lines157158159160161162163171 unmodified lines335336337338339340341342343344345346347348349350351352146 unmodified lines49950050150250350450550650750850924 unmodified lines53453553653753853954054154254354454554654754854955055155255378 unmodified lines632633634635636637638267 unmodified lines90690790890991091191291391491591691791865 unmodified lines98498598698798898999099199299353 unmodified lines104710481049105010511052105310 unmodified lines10641065106610671068106910708 unmodified linesconst GATEWAY_HOST = "127.0.0.1";const startTime = Date.now();const LLM_MODEL = process.env.LLM_MODEL || "Not Set";const TELEGRAM_ENABLED = !!process.env.TELEGRAM_BOT_TOKEN;const WHATSAPP_ENABLED = /^true$/i.test(process.env.WHATSAPP_ENABLED || "");const WHATSAPP_STATUS_FILE = "/tmp/huggingclaw-wa-status.json";15 unmodified lines}function isDashboardRoute(pathname) {return (pathname === "/" ||pathname === DASHBOARD_BASE ||pathname === `${DASHBOARD_BASE}/`);}function isDashboardAppRoute(pathname) {return (pathname === DASHBOARD_APP_BASE ||pathname.startsWith(`${DASHBOARD_APP_BASE}/`));}function isAppRoute(pathname) {12 unmodified lines);}function mapAppProxyPath(path) {if (path === DASHBOARD_APP_BASE) return APP_BASE;if (path.startsWith(`${DASHBOARD_APP_BASE}/`)) {return `${APP_BASE}${path.slice(DASHBOARD_APP_BASE.length)}`;}if (path === APP_BASE || path.startsWith(`${APP_BASE}/`)) {return path;}return path;}72 unmodified lineslet badgeClass = "status-offline";let pulseHtml = "";if (syncData.status === "success" || syncData.status === "configured") {badgeClass = "status-online";pulseHtml = '<div class="pulse"></div>';} else if (syncData.status === "syncing") {5 unmodified lines}function renderDashboard(initialData) {const controlUiHref = `${APP_BASE}/`;return `<!DOCTYPE html><html lang="en">171 unmodified lines#sync-msg { color: var(--text); display: block; margin-top: 4px; }.card-header {display: flex;align-items: center;justify-content: space-between;gap: 12px;margin-bottom: 8px;}.card-header .stat-label {margin-bottom: 0;}.helper-card {width: 100%;margin-top: 20px;146 unmodified linespadding: 16px;}.card-header {align-items: flex-start;flex-direction: column;}.helper-row {flex-direction: column;}24 unmodified lines</div><div class="stat-card"><span class="stat-label">WhatsApp</span><span id="wa-status">${renderChannelBadge(initialData.whatsapp, "Ready to pair")}</span></div><div class="stat-card"><span class="stat-label">Telegram</span><span id="tg-status">${renderChannelBadge(initialData.telegram, "Configured")}</span></div><a href="${controlUiHref}" id="control-ui-link" class="stat-btn">Open Control UI</a></div><div class="stat-card" style="width: 100%;"><div class="card-header"><span class="stat-label">Workspace Sync Status</span><div id="sync-badge-container">${renderSyncBadge(initialData.sync)}</div></div><div class="sync-info">Last Sync Activity: <span id="sync-time">${initialData.sync.timestamp || "Never"}</span><span id="sync-msg">${initialData.sync.message || "Waiting for first sync..."}</span>78 unmodified lineslet badgeClass = 'status-offline';let pulseHtml = '';if (syncData.status === 'success' || syncData.status === 'configured') {badgeClass = 'status-online';pulseHtml = '<div class="pulse"></div>';} else if (syncData.status === 'syncing') {267 unmodified linesreturn forwardedHeaders;}function proxyUpgrade(req,socket,head,proxyPath = req.url,proxyPort = GATEWAY_PORT,) {const proxySocket = net.connect(proxyPort, GATEWAY_HOST);proxySocket.on("connect", () => {65 unmodified linesreturn;}if (pathname === "/uptimerobot/setup" ||pathname === DASHBOARD_UPTIMEROBOT_PATH) {if (req.method !== "POST") {res.writeHead(405, { "Content-Type": "application/json" });res.end(JSON.stringify({ message: "Method not allowed" }));53 unmodified lines}if (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {const proxyPath = mapAppProxyPath(pathname) + (parsedUrl.search || "");proxyHttp(req, res, proxyPath, GATEWAY_PORT);return;}10 unmodified linesif (isDashboardAppRoute(pathname) || isAppRoute(pathname)) {const parsedUrl = parseRequestUrl(req.url || "/");const proxyPath = mapAppProxyPath(pathname) + (parsedUrl.search || "");proxyUpgrade(req, socket, head, proxyPath, GATEWAY_PORT);return;}
health-server.js+53-26