mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-12 16:35:49 +01:00
Ping module rework
This commit is contained in:
@@ -61,6 +61,7 @@
|
|||||||
"next": "12.2.0",
|
"next": "12.2.0",
|
||||||
"next-i18next": "^11.3.0",
|
"next-i18next": "^11.3.0",
|
||||||
"nzbget-api": "^0.0.3",
|
"nzbget-api": "^0.0.3",
|
||||||
|
"ping": "^0.4.2",
|
||||||
"prism-react-renderer": "^1.3.5",
|
"prism-react-renderer": "^1.3.5",
|
||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
@@ -75,6 +76,7 @@
|
|||||||
"@next/eslint-plugin-next": "^12.1.4",
|
"@next/eslint-plugin-next": "^12.1.4",
|
||||||
"@types/dockerode": "^3.3.9",
|
"@types/dockerode": "^3.3.9",
|
||||||
"@types/node": "17.0.1",
|
"@types/node": "17.0.1",
|
||||||
|
"@types/ping": "^0.4.1",
|
||||||
"@types/react": "17.0.1",
|
"@types/react": "17.0.1",
|
||||||
"@types/uuid": "^8.3.4",
|
"@types/uuid": "^8.3.4",
|
||||||
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
"@typescript-eslint/eslint-plugin": "^5.30.7",
|
||||||
|
|||||||
@@ -1,26 +1,21 @@
|
|||||||
import axios from 'axios';
|
import ping from 'ping';
|
||||||
import https from 'https';
|
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
|
|
||||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
// Parse req.body as a ServiceItem
|
// Parse req.body as a ServiceItem
|
||||||
const { url } = req.query;
|
const { url } = req.query;
|
||||||
const agent = new https.Agent({ rejectUnauthorized: false });
|
// Parse url as URL object
|
||||||
await axios
|
const parsedUrl = new URL(url as string);
|
||||||
.get(url as string, { httpsAgent: agent })
|
// Ping the URL
|
||||||
.then((response) => {
|
const response = await ping.promise.probe(parsedUrl.hostname, {
|
||||||
res.status(response.status).json(response.statusText);
|
timeout: 1,
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
if (error.response) {
|
|
||||||
res.status(error.response.status).json(error.response.statusText);
|
|
||||||
} else {
|
|
||||||
res.status(500).json('Server Error');
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
// // Make a request to the URL
|
// Return 200 if the alive property is true
|
||||||
// const response = await axios.get(url);
|
if (response.alive) {
|
||||||
// // Return the response
|
return res.status(200).end();
|
||||||
|
}
|
||||||
|
// Return 404 if the alive property is false
|
||||||
|
return res.status(404).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||||
|
|||||||
28
yarn.lock
28
yarn.lock
@@ -2179,6 +2179,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@types/ping@npm:^0.4.1":
|
||||||
|
version: 0.4.1
|
||||||
|
resolution: "@types/ping@npm:0.4.1"
|
||||||
|
checksum: 9b94837fe66df70558c5a42b0e0c8371b4950ab56b96c42c8df809ff2cf52477dd0a7e01d2e6b38af8bb6683b3dcb54587960b96b4b1f3d40fdb529aea348ad0
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"@types/prettier@npm:^2.1.5":
|
"@types/prettier@npm:^2.1.5":
|
||||||
version: 2.6.3
|
version: 2.6.3
|
||||||
resolution: "@types/prettier@npm:2.6.3"
|
resolution: "@types/prettier@npm:2.6.3"
|
||||||
@@ -4843,6 +4850,7 @@ __metadata:
|
|||||||
"@tanstack/react-query": ^4.2.1
|
"@tanstack/react-query": ^4.2.1
|
||||||
"@types/dockerode": ^3.3.9
|
"@types/dockerode": ^3.3.9
|
||||||
"@types/node": 17.0.1
|
"@types/node": 17.0.1
|
||||||
|
"@types/ping": ^0.4.1
|
||||||
"@types/react": 17.0.1
|
"@types/react": 17.0.1
|
||||||
"@types/uuid": ^8.3.4
|
"@types/uuid": ^8.3.4
|
||||||
"@typescript-eslint/eslint-plugin": ^5.30.7
|
"@typescript-eslint/eslint-plugin": ^5.30.7
|
||||||
@@ -4874,6 +4882,7 @@ __metadata:
|
|||||||
next: 12.2.0
|
next: 12.2.0
|
||||||
next-i18next: ^11.3.0
|
next-i18next: ^11.3.0
|
||||||
nzbget-api: ^0.0.3
|
nzbget-api: ^0.0.3
|
||||||
|
ping: ^0.4.2
|
||||||
prettier: ^2.7.1
|
prettier: ^2.7.1
|
||||||
prism-react-renderer: ^1.3.5
|
prism-react-renderer: ^1.3.5
|
||||||
react: ^18.2.0
|
react: ^18.2.0
|
||||||
@@ -6897,6 +6906,16 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"ping@npm:^0.4.2":
|
||||||
|
version: 0.4.2
|
||||||
|
resolution: "ping@npm:0.4.2"
|
||||||
|
dependencies:
|
||||||
|
q: 1.x
|
||||||
|
underscore: ^1.12.0
|
||||||
|
checksum: 43992c76fb3294734248753f2028d9fab3b919dbfae79a5ea6df7e81fc2d6d555dd0b195d6c3dbc5c89aa9dba1cd8eb58d5ecedad103ecfee64df516e5f3665b
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"pirates@npm:^4.0.4":
|
"pirates@npm:^4.0.4":
|
||||||
version: 4.0.5
|
version: 4.0.5
|
||||||
resolution: "pirates@npm:4.0.5"
|
resolution: "pirates@npm:4.0.5"
|
||||||
@@ -7064,7 +7083,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"q@npm:^1.4.1":
|
"q@npm:1.x, q@npm:^1.4.1":
|
||||||
version: 1.5.1
|
version: 1.5.1
|
||||||
resolution: "q@npm:1.5.1"
|
resolution: "q@npm:1.5.1"
|
||||||
checksum: 147baa93c805bc1200ed698bdf9c72e9e42c05f96d007e33a558b5fdfd63e5ea130e99313f28efc1783e90e6bdb4e48b67a36fcc026b7b09202437ae88a1fb12
|
checksum: 147baa93c805bc1200ed698bdf9c72e9e42c05f96d007e33a558b5fdfd63e5ea130e99313f28efc1783e90e6bdb4e48b67a36fcc026b7b09202437ae88a1fb12
|
||||||
@@ -8177,6 +8196,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"underscore@npm:^1.12.0":
|
||||||
|
version: 1.13.6
|
||||||
|
resolution: "underscore@npm:1.13.6"
|
||||||
|
checksum: d5cedd14a9d0d91dd38c1ce6169e4455bb931f0aaf354108e47bd46d3f2da7464d49b2171a5cf786d61963204a42d01ea1332a903b7342ad428deaafaf70ec36
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"unique-filename@npm:^1.1.1":
|
"unique-filename@npm:^1.1.1":
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
resolution: "unique-filename@npm:1.1.1"
|
resolution: "unique-filename@npm:1.1.1"
|
||||||
|
|||||||
Reference in New Issue
Block a user