From c205189beef53e80efe33b460b67d60617d0710b Mon Sep 17 00:00:00 2001 From: lovefengruoqing Date: Sat, 30 May 2020 14:20:23 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Change=20hostname=20to=20host?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mod.ts | 4 ++-- mod_test.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) 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); +})