mirror of
				https://github.com/karl0ss/homepage.git
				synced 2025-11-04 00:10:57 +00:00 
			
		
		
		
	Retrieve ping url from config rather than as query parameter
This commit is contained in:
		
							parent
							
								
									0d6ccb036e
								
							
						
					
					
						commit
						1fb7be7457
					
				@ -3,7 +3,7 @@ import classNames from "classnames";
 | 
				
			|||||||
import List from "components/services/list";
 | 
					import List from "components/services/list";
 | 
				
			||||||
import ResolvedIcon from "components/resolvedicon";
 | 
					import ResolvedIcon from "components/resolvedicon";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function ServicesGroup({ services, layout, fiveColumns }) {
 | 
					export default function ServicesGroup({ group, services, layout, fiveColumns }) {
 | 
				
			||||||
  return (
 | 
					  return (
 | 
				
			||||||
    <div
 | 
					    <div
 | 
				
			||||||
      key={services.name}
 | 
					      key={services.name}
 | 
				
			||||||
@ -21,7 +21,7 @@ export default function ServicesGroup({ services, layout, fiveColumns }) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
        <h2 className="text-theme-800 dark:text-theme-300 text-xl font-medium">{services.name}</h2>
 | 
					        <h2 className="text-theme-800 dark:text-theme-300 text-xl font-medium">{services.name}</h2>
 | 
				
			||||||
      </div>
 | 
					      </div>
 | 
				
			||||||
      <List services={services.services} layout={layout} />
 | 
					      <List group={group} services={services.services} layout={layout} />
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -11,7 +11,7 @@ import Kubernetes from "widgets/kubernetes/component";
 | 
				
			|||||||
import { SettingsContext } from "utils/contexts/settings";
 | 
					import { SettingsContext } from "utils/contexts/settings";
 | 
				
			||||||
import ResolvedIcon from "components/resolvedicon";
 | 
					import ResolvedIcon from "components/resolvedicon";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Item({ service }) {
 | 
					export default function Item({ service, group }) {
 | 
				
			||||||
  const hasLink = service.href && service.href !== "#";
 | 
					  const hasLink = service.href && service.href !== "#";
 | 
				
			||||||
  const { settings } = useContext(SettingsContext);
 | 
					  const { settings } = useContext(SettingsContext);
 | 
				
			||||||
  const showStats = (service.showStats === false) ? false : settings.showStats;
 | 
					  const showStats = (service.showStats === false) ? false : settings.showStats;
 | 
				
			||||||
@ -77,7 +77,7 @@ export default function Item({ service }) {
 | 
				
			|||||||
          <div className="absolute top-0 right-0 w-1/2 flex flex-row justify-end gap-2 mr-2">
 | 
					          <div className="absolute top-0 right-0 w-1/2 flex flex-row justify-end gap-2 mr-2">
 | 
				
			||||||
              {service.ping && (
 | 
					              {service.ping && (
 | 
				
			||||||
                <div className="flex-shrink-0 flex items-center justify-center cursor-pointer">
 | 
					                <div className="flex-shrink-0 flex items-center justify-center cursor-pointer">
 | 
				
			||||||
                  <Ping service={service} />
 | 
					                  <Ping group={group} service={service.name} />
 | 
				
			||||||
                  <span className="sr-only">Ping status</span>
 | 
					                  <span className="sr-only">Ping status</span>
 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
              )}
 | 
					              )}
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@ const columnMap = [
 | 
				
			|||||||
  "grid-cols-1 md:grid-cols-2 lg:grid-cols-8",
 | 
					  "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 (
 | 
					  return (
 | 
				
			||||||
    <ul
 | 
					    <ul
 | 
				
			||||||
      className={classNames(
 | 
					      className={classNames(
 | 
				
			||||||
@ -23,7 +23,7 @@ export default function List({ services, layout }) {
 | 
				
			|||||||
      )}
 | 
					      )}
 | 
				
			||||||
    >
 | 
					    >
 | 
				
			||||||
      {services.map((service) => (
 | 
					      {services.map((service) => (
 | 
				
			||||||
        <Item key={service.container ?? service.app ?? service.name} service={service} />
 | 
					        <Item key={service.container ?? service.app ?? service.name} service={service} group={group} />
 | 
				
			||||||
      ))}
 | 
					      ))}
 | 
				
			||||||
    </ul>
 | 
					    </ul>
 | 
				
			||||||
  );
 | 
					  );
 | 
				
			||||||
 | 
				
			|||||||
@ -1,9 +1,9 @@
 | 
				
			|||||||
import { useTranslation } from "react-i18next";
 | 
					import { useTranslation } from "react-i18next";
 | 
				
			||||||
import useSWR from "swr";
 | 
					import useSWR from "swr";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default function Ping({ service }) {
 | 
					export default function Ping({ group, service }) {
 | 
				
			||||||
  const { t } = useTranslation();
 | 
					  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
 | 
					    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) {
 | 
					  if (data.status > 403) {
 | 
				
			||||||
    return (
 | 
					    return (
 | 
				
			||||||
 | 
				
			|||||||
@ -1,12 +1,22 @@
 | 
				
			|||||||
import { performance } from "perf_hooks";
 | 
					import { performance } from "perf_hooks";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import { getServiceItem } from "utils/config/service-helpers";
 | 
				
			||||||
import createLogger from "utils/logger";
 | 
					import createLogger from "utils/logger";
 | 
				
			||||||
import { httpProxy } from "utils/proxy/http";
 | 
					import { httpProxy } from "utils/proxy/http";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const logger = createLogger("ping");
 | 
					const logger = createLogger("ping");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default async function handler(req, res) {
 | 
					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) {
 | 
					    if (!pingURL) {
 | 
				
			||||||
        logger.debug("No ping URL specified");
 | 
					        logger.debug("No ping URL specified");
 | 
				
			||||||
 | 
				
			|||||||
@ -289,7 +289,7 @@ function Home({ initialSettings }) {
 | 
				
			|||||||
        {services?.length > 0 && (
 | 
					        {services?.length > 0 && (
 | 
				
			||||||
          <div className="flex flex-wrap p-4 sm:p-8 sm:pt-4 items-start pb-2">
 | 
					          <div className="flex flex-wrap p-4 sm:p-8 sm:pt-4 items-start pb-2">
 | 
				
			||||||
            {services.map((group) => (
 | 
					            {services.map((group) => (
 | 
				
			||||||
              <ServicesGroup key={group.name} services={group} layout={initialSettings.layout?.[group.name]} fiveColumns={settings.fiveColumns} />
 | 
					              <ServicesGroup key={group.name} group={group.name} services={group} layout={initialSettings.layout?.[group.name]} fiveColumns={settings.fiveColumns} />
 | 
				
			||||||
            ))}
 | 
					            ))}
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
        )}
 | 
					        )}
 | 
				
			||||||
 | 
				
			|||||||
@ -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 configuredServices = await servicesFromConfig();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const serviceGroup = configuredServices.find((g) => g.name === group);
 | 
					  const serviceGroup = configuredServices.find((g) => g.name === group);
 | 
				
			||||||
  if (serviceGroup) {
 | 
					  if (serviceGroup) {
 | 
				
			||||||
    const serviceEntry = serviceGroup.services.find((s) => s.name === service);
 | 
					    const serviceEntry = serviceGroup.services.find((s) => s.name === service);
 | 
				
			||||||
    if (serviceEntry) {
 | 
					    if (serviceEntry) return serviceEntry;
 | 
				
			||||||
      const { widget } = serviceEntry;
 | 
					 | 
				
			||||||
      return widget;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const discoveredServices = await servicesFromDocker();
 | 
					  const discoveredServices = await servicesFromDocker();
 | 
				
			||||||
@ -345,20 +342,24 @@ export default async function getServiceWidget(group, service) {
 | 
				
			|||||||
  const dockerServiceGroup = discoveredServices.find((g) => g.name === group);
 | 
					  const dockerServiceGroup = discoveredServices.find((g) => g.name === group);
 | 
				
			||||||
  if (dockerServiceGroup) {
 | 
					  if (dockerServiceGroup) {
 | 
				
			||||||
    const dockerServiceEntry = dockerServiceGroup.services.find((s) => s.name === service);
 | 
					    const dockerServiceEntry = dockerServiceGroup.services.find((s) => s.name === service);
 | 
				
			||||||
    if (dockerServiceEntry) {
 | 
					    if (dockerServiceEntry) return dockerServiceEntry;
 | 
				
			||||||
      const { widget } = dockerServiceEntry;
 | 
					 | 
				
			||||||
      return widget;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const kubernetesServices = await servicesFromKubernetes();
 | 
					  const kubernetesServices = await servicesFromKubernetes();
 | 
				
			||||||
  const kubernetesServiceGroup = kubernetesServices.find((g) => g.name === group);
 | 
					  const kubernetesServiceGroup = kubernetesServices.find((g) => g.name === group);
 | 
				
			||||||
  if (kubernetesServiceGroup) {
 | 
					  if (kubernetesServiceGroup) {
 | 
				
			||||||
    const kubernetesServiceEntry = kubernetesServiceGroup.services.find((s) => s.name === service);
 | 
					    const kubernetesServiceEntry = kubernetesServiceGroup.services.find((s) => s.name === service);
 | 
				
			||||||
    if (kubernetesServiceEntry) {
 | 
					    if (kubernetesServiceEntry) return kubernetesServiceEntry;
 | 
				
			||||||
      const { widget } = kubernetesServiceEntry;
 | 
					  }
 | 
				
			||||||
      return widget;
 | 
					
 | 
				
			||||||
    }
 | 
					  return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default async function getServiceWidget(group, service) {
 | 
				
			||||||
 | 
					  const serviceItem = await getServiceItem(group, service);
 | 
				
			||||||
 | 
					  if (serviceItem) {
 | 
				
			||||||
 | 
					    const { widget } = serviceItem;
 | 
				
			||||||
 | 
					    return widget;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  return false;
 | 
					  return false;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user