rewrite monitor resolution check, update tests

This commit is contained in:
Alex Holliday committed 2024-11-20 10:37:01 +08:00
1 parent cb0271613e
commit 58be0c018b
2 files changed
+21 -21

No files matched your search

+8 -10
View File
@@ -19,7 +19,7 @@ import jwt from "jsonwebtoken";
import { getTokenFromHeaders } from "../utils/utils.js";
import logger from "../utils/logger.js";
import { handleError, handleValidationError } from "./controllerUtils.js";
import dns from "dns";
import axios from "axios";
const SERVICE_NAME = "monitorController";
@@ -288,18 +288,16 @@ const checkEndpointResolution = async (req, res, next) => {
}
try {
let { monitorURL } = req.query;
monitorURL = new URL(monitorURL);
await new Promise((resolve, reject) => {
dns.resolve(monitorURL.hostname, (error) => {
if (error) {
reject(error);
}
resolve();
});
const { monitorURL } = req.query;
const parsedUrl = new URL(monitorURL);
const response = await axios.get(parsedUrl, {
timeout: 5000,
validateStatus: () => true,
});
return res.status(200).json({
success: true,
code: response.status,
statusText: response.statusText,
msg: `URL resolved successfully`,
});
} catch (error) {