diff --git a/mod.ts b/mod.ts index 1f37d89..418f4a2 100644 --- a/mod.ts +++ b/mod.ts @@ -1,6 +1,6 @@ /** Check if a website is up */ export async function isUp(url: string): Promise { - const hostname = encodeURIComponent((new URL(url)).hostname); + const host = encodeURIComponent((new URL(url)).host); const result: { "domain": string; "port": number; @@ -8,7 +8,7 @@ export async function isUp(url: string): Promise { "response_ip": string; "response_code": number; "response_time": number; - } = await (await fetch(`https://isitup.org/${hostname}.json`)) + } = await (await fetch(`https://isitup.org/${host}.json`)) .json(); return result.status_code === 1; } diff --git a/mod_test.ts b/mod_test.ts index 0b0cc7e..3b1cf6b 100644 --- a/mod_test.ts +++ b/mod_test.ts @@ -10,3 +10,13 @@ Deno.test("should be down", async (): Promise => { false, ); }); + +/** + * The official website of deno is: https://deno.land/ + * Website remote address: 172.67.163.168:443 + * The official website of Deno does not allow users to access content through IP addresses, + * but in some cases, I may need this method to test my personal server. + */ +Deno.test("deno remote address test", async (): Promise => { + assertEquals(await isUp("http://172.67.163.168:443"), true); +})