Public
Cron
Forked from thierryc/isMyWebsiteDown
Runs every 1 hrs
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
import { email } from "https://esm.town/v/std/email";
export const isMyWebsiteDown = async () => {
// Replace this URL with the website you want to track
const URL = "https://andreterron.com";
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} (UTC), ${URL} was down (reason: ${reason}).`;
console.log(subject, text);
await email({ subject, text });
} else {
console.log("Website ok");
}
};
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
March 20, 2024
Getting an error when running this.
TypeError: Expected a JavaScript or TypeScript module, but identified a Unknown module. Importing these types of modules is currently not supported. Specifier: https://www.google.com/ at https://esm.town/v/xxx/isMyWebsiteDown?v=2:1:23 val at async https://esm.town/guest.ts?x=1254a223eee5da7bc49134e0512ac72d:382:19
Hey @advantis! I looked at your profile and made a PR to fix your val.
In summary, the first URL is where we're importing the
email
utility from. To check your website, you should update it on line 5.Hope this helps!