Skip to content

ServerKit is a lightweight, modern server control panel for managing web applications, databases, and services on your VPS or dedicated server. Built with Python/Flask backend and React frontend.

fix(services): show the logs and usage that were there all along

Juan Denisa15a78a1cda6
diff --git a/frontend/src/components/appdetail/LogsTab.jsx b/frontend/src/components/appdetail/LogsTab.jsx
index 22a714e2..7f3c7069 100644
--- a/frontend/src/components/appdetail/LogsTab.jsx
+++ b/frontend/src/components/appdetail/LogsTab.jsx
@@ -1,4 +1,5 @@
import { useState, useEffect } from 'react';
+import { logsToText } from '@/utils/logText';
import api from '../../services/api';
import { Button } from '@/components/ui/button';
@@ -30,7 +31,7 @@ const LogsTab = ({ app }) => {
} else {
data = { logs: 'Logs not available for this app type.' };
}
- setLogs(data.logs || 'No logs available');
+ setLogs(logsToText(data) || 'No logs available');
} catch (err) {
console.error('Failed to load logs:', err);
setLogs('Failed to load logs');
diff --git a/frontend/src/components/service-detail/LogsTab.jsx b/frontend/src/components/service-detail/LogsTab.jsx
index 75616ae3..cc61c5b1 100644
--- a/frontend/src/components/service-detail/LogsTab.jsx
+++ b/frontend/src/components/service-detail/LogsTab.jsx
@@ -1,5 +1,6 @@
import { useState, useEffect, useRef, useMemo } from 'react';
import { useSearchParams } from 'react-router-dom';
+import { logsToText } from '@/utils/logText';
import api from '../../services/api';
import { useToast } from '../../contexts/ToastContext';
import { useLogsDrawer } from '../../contexts/LogsDrawerContext';
@@ -75,7 +76,7 @@ const LogsTab = ({ app }) => {
} else {
data = { logs: 'Logs not available for this app type.' };
}
- setRawLogs(data.logs || 'No logs available');
+ setRawLogs(logsToText(data) || 'No logs available');
} catch (err) {
console.error('Failed to load logs:', err);
setRawLogs('Failed to load logs');
diff --git a/frontend/src/components/service-detail/OverviewTab.jsx b/frontend/src/components/service-detail/OverviewTab.jsx
index 2b81c628..3f867a47 100644
--- a/frontend/src/components/service-detail/OverviewTab.jsx
+++ b/frontend/src/components/service-detail/OverviewTab.jsx
@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react';
import { Link } from 'react-router-dom';
-import { Activity, Rocket, CheckCircle2, XCircle, Globe, Database, ShieldCheck } from 'lucide-react';
+import { Activity, Rocket, CheckCircle2, XCircle, Globe, Database, ShieldCheck, ExternalLink } from 'lucide-react';
+import { servicePortUrl } from '@/utils/serviceUrl';
import api from '../../services/api';
import { useDeployments } from '../../hooks/useDeployments';
import { getDeployStatus, formatRelativeTime, formatDuration } from '../../utils/serviceTypes';
@@ -63,12 +64,21 @@ const OverviewTab = ({ app, deployConfig }) => {
try {
if (isDocker) {
const data = await api.getContainers(true);
- const appContainers = (data.containers || []).filter(c =>
- c.Names?.some(n => n.includes(app.name)) ||
- c.Labels?.['com.docker.compose.project'] === app.name
- );
+ // The API normalises `docker ps` into lowercase keys and does
+ // not expose Labels at all, so matching on `Names[]` and the
+ // compose-project label found nothing — Resource Usage came up
+ // empty for every Docker service. The project can still be
+ // matched through the container name it produces
+ // (project-service-N).
+ const needle = (app.name || '').toLowerCase();
+ const appContainers = (data.containers || []).filter((c) => {
+ const raw = c.name ?? c.Names ?? '';
+ const text = Array.isArray(raw) ? raw.join(',') : String(raw);
+ return needle && text.toLowerCase().includes(needle);
+ });
if (appContainers.length > 0) {
- const containerStats = await api.getContainerStats(appContainers[0].Id);
+ const containerStats = await api.getContainerStats(
+ appContainers[0].id ?? appContainers[0].Id);
setMetrics({
cpu: parseFloat(containerStats.cpu_percent || containerStats.CPUPerc || 0),
memory: parseFloat(containerStats.memory_percent || containerStats.MemPerc || 0),
@@ -94,6 +104,9 @@ const OverviewTab = ({ app, deployConfig }) => {
}
}
+ // No link when a domain fronts it — the Domain row above is the one to follow.
+ const portUrl = app.domain ? null : servicePortUrl(app);
+
const successfulDeploys = deployments.filter(d => d.status === 'success');
const failedDeploys = deployments.filter(d => d.status === 'failed');
@@ -166,7 +179,23 @@ const OverviewTab = ({ app, deployConfig }) => {
{app.port && (
<div className="sk-info-row">
<span className="k">Port</span>
- <span className="v">{app.port}</span>
+ <span className="v">
+ {/* A port with no domain in front of it is
+ still reachable — the number alone made
+ you assemble the URL yourself. */}
+ {portUrl ? (
+ <a
+ href={portUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="overview-tab__info-link"
+ title={`Open ${portUrl}`}
+ >
+ {app.port}
+ <ExternalLink size={10} />
+ </a>
+ ) : app.port}
+ </span>
</div>
)}
<div className="sk-info-row">
diff --git a/frontend/src/pages/ServiceDetail.jsx b/frontend/src/pages/ServiceDetail.jsx
index 6ce3a0f7..5896893d 100644
--- a/frontend/src/pages/ServiceDetail.jsx
+++ b/frontend/src/pages/ServiceDetail.jsx
@@ -1,5 +1,6 @@
import { useState, useEffect, useRef } from 'react';
import { useParams, useNavigate, Link } from 'react-router-dom';
+import { servicePortUrl } from '@/utils/serviceUrl';
import api from '../services/api';
import { useToast } from '../contexts/ToastContext';
import { useConfirm } from '../hooks/useConfirm';
@@ -22,7 +23,7 @@ import OverviewTab from '../components/service-detail/OverviewTab';
import PreviewList from '../components/previews/PreviewList';
import EmptyState from '../components/EmptyState';
import PluginSlot from '../components/PluginSlot';
-import { Layers, FileArchive, RotateCcw, LayoutDashboard, History, ScrollText, Variable, Terminal, Activity, Package, Server, SquareTerminal, Settings, Eye } from 'lucide-react';
+import { Layers, FileArchive, RotateCcw, LayoutDashboard, History, ScrollText, Variable, Terminal, Activity, Package, Server, SquareTerminal, Settings, Eye, ExternalLink } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Pill, ServiceTile, PageTopbar } from '@/components/ds';
@@ -259,6 +260,9 @@ const ServiceDetail = () => {
const isManual = service.source === 'manual';
const domains = service.domains || [];
const primaryDomain = (domains.find(d => d.is_primary) || domains[0])?.name || '';
+ // Only when there is no domain in front of it — otherwise the domain
+ // link above is the one to follow.
+ const openUrl = primaryDomain ? null : servicePortUrl(service);
return (
<div className="app-detail-page app-detail-page--wide svc-detail">
@@ -397,6 +401,20 @@ const ServiceDetail = () => {
<div className="app-detail-title-block">
<h1>
{service.name}
+ {/* Before the status pill: the first thing you want
+ after seeing a service is live is to go look at it. */}
+ {openUrl && (
+ <a
+ href={openUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="svc-detail__open"
+ title={`Open ${openUrl}`}
+ aria-label={`Open ${service.name} in a new tab`}
+ >
+ <ExternalLink size={15} />
+ </a>
+ )}
<Pill kind={STATUS_PILL[service.statusInfo.dotClass] || 'gray'}>
{service.statusInfo.label}
</Pill>
@@ -408,7 +426,22 @@ const ServiceDetail = () => {
</span>
</h1>
<div className="app-detail-subtitle">
- {service.port && <span>Port {service.port}</span>}
+ {service.port && (
+ openUrl ? (
+ <a
+ href={openUrl}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="svc-detail__portlink"
+ title={`Open ${openUrl}`}
+ >
+ Port {service.port}
+ <ExternalLink size={12} />
+ </a>
+ ) : (
+ <span>Port {service.port}</span>
+ )
+ )}
{service.port && <span className="separator">&middot;</span>}
<span>Created {new Date(service.created_at).toLocaleDateString()}</span>
{primaryDomain && (
diff --git a/frontend/src/styles/pages/_service-detail.scss b/frontend/src/styles/pages/_service-detail.scss
index 0042d9bd..d5aec994 100644
--- a/frontend/src/styles/pages/_service-detail.scss
+++ b/frontend/src/styles/pages/_service-detail.scss
@@ -1538,3 +1538,17 @@ h3.svc-eyebrow {
padding: 0 1px;
}
}
+
+// Open-in-new-tab affordance next to the service name, before the status pill.
+.svc-detail__open,
+.svc-detail__portlink {
+ display: inline-flex;
+ align-items: center;
+ gap: 4px;
+ color: $text-tertiary;
+ transition: color $transition-fast;
+
+ &:hover { color: var(--accent-bright); }
+}
+
+.svc-detail__open { margin-left: 2px; }
diff --git a/frontend/src/utils/logText.js b/frontend/src/utils/logText.js
new file mode 100644
index 00000000..33850a0e
--- /dev/null
+++ b/frontend/src/utils/logText.js
@@ -0,0 +1,31 @@
+// Normalise a logs API response into displayable text.
+//
+// The two log paths return different shapes and always have: a local Docker app
+// answers with the standard multi-source envelope (`lines[]`, `source`,
+// `source_label` — see backend `sourced_result`), while a remote one comes back
+// from the agent as a single `logs` string. Readers that only knew about `logs`
+// showed "No logs available" for every local app no matter how much output
+// there was, because the field they checked simply is not in that response.
+//
+// Returns '' when there is genuinely nothing, so callers can tell empty output
+// apart from a failed request.
+export function logsToText(data) {
+ if (!data) return '';
+ if (typeof data === 'string') return data;
+ if (typeof data.logs === 'string' && data.logs) return data.logs;
+ if (Array.isArray(data.lines)) {
+ return data.lines
+ // A trailing '' from splitting on \n is noise, but blank lines in
+ // the middle of the output are real and worth keeping.
+ .filter((line, i, all) => line !== '' || (i > 0 && i < all.length - 1))
+ .join('\n');
+ }
+ return '';
+}
+
+// Which backend the output came from ('Docker Compose', 'Docker Compose
+// (legacy)', ...), when the response says. Worth showing: it explains an empty
+// log more often than the log itself does.
+export function logsSourceLabel(data) {
+ return (data && typeof data === 'object' && data.source_label) || '';
+}
diff --git a/frontend/src/utils/serviceUrl.js b/frontend/src/utils/serviceUrl.js
new file mode 100644
index 00000000..ad299b2a
--- /dev/null
+++ b/frontend/src/utils/serviceUrl.js
@@ -0,0 +1,20 @@
+// Where a service can actually be opened in a browser.
+//
+// A published domain is the real answer when there is one; this covers the
+// other common case — a container with nothing in front of it but a port, which
+// the panel used to render as the dead text "Port 3001" with no way to reach it.
+export function servicePortUrl(service) {
+ if (!service?.port) return null;
+ // Running only: linking to a stopped container just produces a refused
+ // connection, which reads as the panel being wrong rather than the app
+ // being down.
+ if (service.status && service.status !== 'running') return null;
+ // Apps on a remote server are deliberately excluded. The payload carries
+ // `server_name`, which is a label ("Production box"), not a hostname —
+ // guessing an address from it would hand out links that quietly fail.
+ if (service.server_id) return null;
+ // The panel and the container share a host in this case, so whatever host
+ // the panel is being viewed on is the one to use. Always http: a bare
+ // published port has no certificate.
+ return `http://${window.location.hostname}:${service.port}`;
+}