From 1fb7be7457188013b4afa5150b4ea8591e561c93 Mon Sep 17 00:00:00 2001
From: shamoon <4887959+shamoon@users.noreply.github.com>
Date: Sun, 11 Jun 2023 09:50:41 -0700
Subject: [PATCH] Retrieve ping url from config rather than as query parameter
---
src/components/services/group.jsx | 4 ++--
src/components/services/item.jsx | 4 ++--
src/components/services/list.jsx | 4 ++--
src/components/services/ping.jsx | 6 +++---
src/pages/api/ping.js | 12 +++++++++++-
src/pages/index.jsx | 2 +-
src/utils/config/service-helpers.js | 27 ++++++++++++++-------------
7 files changed, 35 insertions(+), 24 deletions(-)
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 (
{service.ping && (
)}
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;