Skip to content

Commit c7c8523

Browse files
Merge pull request #2 from lovefengruoqing/master
πŸ“ Change hostname to host
2 parents 3532513 + c205189 commit c7c8523

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

β€Žmod.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/** Check if a website is up */
22
export async function isUp(url: string): Promise<boolean> {
3-
const hostname = encodeURIComponent((new URL(url)).hostname);
3+
const host = encodeURIComponent((new URL(url)).host);
44
const result: {
55
"domain": string;
66
"port": number;
77
"status_code": 1 | 2 | 3;
88
"response_ip": string;
99
"response_code": number;
1010
"response_time": number;
11-
} = await (await fetch(`https://isitup.org/${hostname}.json`))
11+
} = await (await fetch(`https://isitup.org/${host}.json`))
1212
.json();
1313
return result.status_code === 1;
1414
}

β€Žmod_test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,13 @@ Deno.test("should be down", async (): Promise<void> => {
1010
false,
1111
);
1212
});
13+
14+
/**
15+
* The official website of deno is: https://deno.land/
16+
* Website remote address: 172.67.163.168:443
17+
* The official website of Deno does not allow users to access content through IP addresses,
18+
* but in some cases, I may need this method to test my personal server.
19+
*/
20+
Deno.test("deno remote address test", async (): Promise<void> => {
21+
assertEquals(await isUp("http://172.67.163.168:443"), true);
22+
})

0 commit comments

Comments
Β (0)