From 7685333aedaf6de6696b10b6daa4f139728b959e Mon Sep 17 00:00:00 2001 From: Anand Chowdhary Date: Sun, 10 Dec 2023 20:05:29 +0100 Subject: [PATCH] :bug: Fix TypeScript syntax, update IP condition --- src/update.ts | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/update.ts b/src/update.ts index 9f2b6692..393678f4 100644 --- a/src/update.ts +++ b/src/update.ts @@ -156,19 +156,18 @@ export const update = async (shouldCommit = false) => { try { let status: "up" | "down" | "degraded" = "up"; // https://github.com/upptime/upptime/discussions/888 - const url = replaceEnvironmentVariables(site.url), - let address; - if (isIP(url)) { + const url = replaceEnvironmentVariables(site.url); + let address = url; + if (isIP(url) { if (site.ipv6 && !isIPv6(url)) - throw Error('Site URL must be IPv6 for ipv6 check'); - address = url; - } else { - if (site.ipv6) + throw new Error("Site URL must be IPv6 for ipv6 check"); + else if (site.ipv6) address = (await dns.promises.resolve6(url))[0]; else address = (await dns.promises.resolve4(url))[0]; - if (!isIP(address)) - throw Error('Site IP address could not be resolved'); + + if (isIP(url) && !isIP(address)) + throw new Error("Site IP address could not be resolved"); } const tcpResult = await ping({