Skip to content

Commit

Permalink
Merge pull request #2 from lovefengruoqing/master
Browse files Browse the repository at this point in the history
πŸ“ Change hostname to host
  • Loading branch information
AnandChowdhary authored May 30, 2020
2 parents 3532513 + c205189 commit c7c8523
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/** Check if a website is up */
export async function isUp(url: string): Promise<boolean> {
const hostname = encodeURIComponent((new URL(url)).hostname);
const host = encodeURIComponent((new URL(url)).host);
const result: {
"domain": string;
"port": number;
"status_code": 1 | 2 | 3;
"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;
}
Expand Down
10 changes: 10 additions & 0 deletions mod_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,13 @@ Deno.test("should be down", async (): Promise<void> => {
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<void> => {
assertEquals(await isUp("http://172.67.163.168:443"), true);
})

0 comments on commit c7c8523

Please sign in to comment.