diff --git a/src/components/services/group.jsx b/src/components/services/group.jsx index 5f1c54464..945570647 100644 --- a/src/components/services/group.jsx +++ b/src/components/services/group.jsx @@ -3,7 +3,7 @@ import classNames from "classnames"; import List from "components/services/list"; import ResolvedIcon from "components/resolvedicon"; -export default function ServicesGroup({ services, layout, fiveColumns }) { +export default function ServicesGroup({ group, services, layout, fiveColumns }) { return (
{services.name}
- + ); } diff --git a/src/components/services/item.jsx b/src/components/services/item.jsx index 08b8d1f42..36e454cef 100644 --- a/src/components/services/item.jsx +++ b/src/components/services/item.jsx @@ -11,7 +11,7 @@ import Kubernetes from "widgets/kubernetes/component"; import { SettingsContext } from "utils/contexts/settings"; import ResolvedIcon from "components/resolvedicon"; -export default function Item({ service }) { +export default function Item({ service, group }) { const hasLink = service.href && service.href !== "#"; const { settings } = useContext(SettingsContext); const showStats = (service.showStats === false) ? false : settings.showStats; @@ -77,7 +77,7 @@ export default function Item({ service }) {
{service.ping && (
- + Ping status
)} diff --git a/src/components/services/list.jsx b/src/components/services/list.jsx index c8028df50..85083af3c 100644 --- a/src/components/services/list.jsx +++ b/src/components/services/list.jsx @@ -14,7 +14,7 @@ const columnMap = [ "grid-cols-1 md:grid-cols-2 lg:grid-cols-8", ]; -export default function List({ services, layout }) { +export default function List({ group, services, layout }) { return (
    {services.map((service) => ( - + ))}
); diff --git a/src/components/services/ping.jsx b/src/components/services/ping.jsx index a54b1b556..291bc9e02 100644 --- a/src/components/services/ping.jsx +++ b/src/components/services/ping.jsx @@ -1,9 +1,9 @@ import { useTranslation } from "react-i18next"; import useSWR from "swr"; -export default function Ping({ service }) { +export default function Ping({ group, service }) { const { t } = useTranslation(); - const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ping: service.ping}).toString()}`, { + const { data, error } = useSWR(`/api/ping?${new URLSearchParams({ group, service }).toString()}`, { refreshInterval: 30000 }); @@ -23,7 +23,7 @@ export default function Ping({ service }) { ); } - const statusText = `${service.ping}: HTTP status ${data.status}`; + const statusText = `${service}: HTTP status ${data.status}`; if (data.status > 403) { return ( diff --git a/src/pages/api/ping.js b/src/pages/api/ping.js index 96c1b12cc..cfc2aafa8 100644 --- a/src/pages/api/ping.js +++ b/src/pages/api/ping.js @@ -1,12 +1,22 @@ import { performance } from "perf_hooks"; +import { getServiceItem } from "utils/config/service-helpers"; import createLogger from "utils/logger"; import { httpProxy } from "utils/proxy/http"; const logger = createLogger("ping"); export default async function handler(req, res) { - const { ping: pingURL } = req.query; + const { group, service } = req.query; + const serviceItem = await getServiceItem(group, service); + if (!serviceItem) { + logger.debug(`No service item found for group ${group} named ${service}`); + return res.status(400).send({ + error: "Unable to find service, see log for details.", + }); + } + + const { ping: pingURL } = serviceItem; if (!pingURL) { logger.debug("No ping URL specified"); diff --git a/src/pages/index.jsx b/src/pages/index.jsx index e170d4e1d..6180ff51e 100644 --- a/src/pages/index.jsx +++ b/src/pages/index.jsx @@ -289,7 +289,7 @@ function Home({ initialSettings }) { {services?.length > 0 && (
{services.map((group) => ( - + ))}
)} diff --git a/src/utils/config/service-helpers.js b/src/utils/config/service-helpers.js index c63fa8f2d..d4f7bc4e3 100644 --- a/src/utils/config/service-helpers.js +++ b/src/utils/config/service-helpers.js @@ -328,16 +328,13 @@ export function cleanServiceGroups(groups) { })); } -export default async function getServiceWidget(group, service) { +export async function getServiceItem(group, service) { const configuredServices = await servicesFromConfig(); const serviceGroup = configuredServices.find((g) => g.name === group); if (serviceGroup) { const serviceEntry = serviceGroup.services.find((s) => s.name === service); - if (serviceEntry) { - const { widget } = serviceEntry; - return widget; - } + if (serviceEntry) return serviceEntry; } const discoveredServices = await servicesFromDocker(); @@ -345,20 +342,24 @@ export default async function getServiceWidget(group, service) { const dockerServiceGroup = discoveredServices.find((g) => g.name === group); if (dockerServiceGroup) { const dockerServiceEntry = dockerServiceGroup.services.find((s) => s.name === service); - if (dockerServiceEntry) { - const { widget } = dockerServiceEntry; - return widget; - } + if (dockerServiceEntry) return dockerServiceEntry; } const kubernetesServices = await servicesFromKubernetes(); const kubernetesServiceGroup = kubernetesServices.find((g) => g.name === group); if (kubernetesServiceGroup) { const kubernetesServiceEntry = kubernetesServiceGroup.services.find((s) => s.name === service); - if (kubernetesServiceEntry) { - const { widget } = kubernetesServiceEntry; - return widget; - } + if (kubernetesServiceEntry) return kubernetesServiceEntry; + } + + return false; +} + +export default async function getServiceWidget(group, service) { + const serviceItem = await getServiceItem(group, service); + if (serviceItem) { + const { widget } = serviceItem; + return widget; } return false;