mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-09 23:15:46 +01:00
🚑️ Ping array (#823)
This commit is contained in:
@@ -96,6 +96,7 @@ export const AvailableElementTypes = ({
|
||||
network: {
|
||||
enabledStatusChecker: true,
|
||||
statusCodes: ['200'],
|
||||
okStatus: [200],
|
||||
},
|
||||
behaviour: {
|
||||
isOpeningNewTab: true,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Indicator, Tooltip } from '@mantine/core';
|
||||
import Consola from 'consola';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -19,7 +20,7 @@ export const AppPing = ({ app }: AppPingProps) => {
|
||||
queryKey: ['ping', { id: app.id, name: app.name }],
|
||||
queryFn: async () => {
|
||||
const response = await fetch(`/api/modules/ping?url=${encodeURI(app.url)}`);
|
||||
const isOk = app.network.statusCodes.includes(response.status.toString());
|
||||
const isOk = getIsOk(app, response.status);
|
||||
return {
|
||||
status: response.status,
|
||||
state: isOk ? 'online' : 'down',
|
||||
@@ -60,3 +61,12 @@ export const AppPing = ({ app }: AppPingProps) => {
|
||||
</motion.div>
|
||||
);
|
||||
};
|
||||
|
||||
const getIsOk = (app: AppType, status: number) => {
|
||||
if (app.network.okStatus === undefined || app.network.statusCodes.length >= 1) {
|
||||
Consola.log('Using new status codes');
|
||||
return app.network.statusCodes.includes(status.toString());
|
||||
}
|
||||
Consola.warn('Using deprecated okStatus');
|
||||
return app.network.okStatus.includes(status);
|
||||
};
|
||||
|
||||
@@ -178,6 +178,7 @@ export default function ContainerActionBar({ selected, reload }: ContainerAction
|
||||
network: {
|
||||
enabledStatusChecker: true,
|
||||
statusCodes: ['200'],
|
||||
okStatus: [200],
|
||||
},
|
||||
behaviour: {
|
||||
isOpeningNewTab: true,
|
||||
|
||||
@@ -35,6 +35,13 @@ function Put(req: NextApiRequest, res: NextApiResponse) {
|
||||
apps: [
|
||||
...config.apps.map((app) => ({
|
||||
...app,
|
||||
network: {
|
||||
...app.network,
|
||||
statusCodes: app.network.okStatus === undefined ?
|
||||
app.network.statusCodes :
|
||||
app.network.okStatus.map((x) => x.toString()),
|
||||
okStatus: undefined,
|
||||
},
|
||||
integration: {
|
||||
...app.integration,
|
||||
properties: app.integration.properties.map((property) => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import axios from 'axios';
|
||||
import https from 'https';
|
||||
import Consola from 'consola';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -13,6 +14,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.response) {
|
||||
Consola.error(`Unexpected response: ${error.response.data}`);
|
||||
res.status(error.response.status).json(error.response.statusText);
|
||||
} else if (error.code === 'ECONNABORTED') {
|
||||
res.status(408).json('Request Timeout');
|
||||
|
||||
@@ -23,6 +23,7 @@ interface AppBehaviourType {
|
||||
|
||||
interface AppNetworkType {
|
||||
enabledStatusChecker: boolean;
|
||||
okStatus?: number[];
|
||||
statusCodes: string[];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user