1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { email } from "https://esm.town/v/std/email";
const URLS = [
"https://think.ing.com",
"https://terralemon.nl",
];
const isMyWebsiteDown = async (URL) => {
// Replace this URL with the website you want to track
const [date, time] = new Date().toISOString().split("T");
let ok = true;
let reason: string;
try {
const res = await fetch(URL, { redirect: "follow" });
if (res.status !== 200) {
reason = `(status code: ${res.status})`;
ok = false;
}
} catch (e) {
reason = `couldn't fetch: ${e}`;
ok = false;
}
if (!ok) {
const subject = `Website down (${URL})`;
const text = `At ${date} ${time}, ${URL} was down (reason: ${reason}).`;
console.log(subject, text);
await email({ subject, text });
} else {
console.log(`${URL} is up!`);
}
};
const main = async () => {
for (const URL of URLS) {
await isMyWebsiteDown(URL);
}
};
export default main;