Avatar

devonzuegel

3 public vals
Joined February 5, 2024

Emails me if my personal website is down. (If you fork this, it'll email you, since you'll be the owner of the new fork.)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import { email } from "https://esm.town/v/std/email";
import { fetch } from "https://esm.town/v/std/fetch";
export const isMyWebsiteDown = async () => {
const URL = "https://devonzuegel.com";
const [date, time] = new Date().toISOString().split("T");
let ok = true;
let reason: string;
try {
const res = await fetch(URL);
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}).`;
email({ subject, text });
}
};
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
// I was able to get this script to work from my browser console, but
// it's not working in ValTown or from Airtable's scripting environment.
// My best guess is that it has something to do with the headers not looking
// quite right to Substack when we hit their API.
const email = "hello.at.smallworld@gmail.com";
const body = {
additional_referring_pub_ids: "",
current_referrer: "",
current_url: "https://blog.edgeesmeralda.com/",
first_referrer: "",
first_url: "https://blog.edgeesmeralda.com/",
referral_code: "",
referring_pub_id: "",
source: "cover_page",
email,
};
const result = await fetch("https://blog.edgeesmeralda.com/api/v1/free", {
"headers": {
"content-type": "application/json",
"sec-ch-ua": "\"Not A(Brand\";v=\"99\", \"Google Chrome\";v=\"121\", \"Chromium\";v=\"121\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
"Referer": "https://blog.edgeesmeralda.com/",
"Referrer-Policy": "strict-origin-when-cross-origin",
},
"body": JSON.stringify(body),
"method": "POST",
});
console.log(await result.json());
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// I was able to get this script to work from my browser console, but
// it's not working in ValTown or from Airtable's scripting environment.
// My best guess is that it has something to do with the headers not looking
// quite right to Substack when we hit their API.
const email = "avery.sara.james@gmail.com";
const result = await fetch("https://blog.edgeesmeralda.com/api/v1/free", {
"headers": {
"content-type": "application/json",
"sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
"sec-ch-ua-mobile": "?0",
"sec-ch-ua-platform": "\"macOS\"",
},
"referrer": "https://blog.edgeesmeralda.com/",
"referrerPolicy": "strict-origin-when-cross-origin",
"body":
`{\"first_url\":\"https://blog.edgeesmeralda.com/\",\"first_referrer\":\"\",\"current_url\":\"https://blog.edgeesmeralda.com/\",\"current_referrer\":\"\",\"referral_code\":\"\",\"source\":\"home-sitemap\",\"referring_pub_id\":\"\",\"additional_referrin
"method": "POST",
"mode": "cors",
"credentials": "omit",
});
console.log(await result.text());
Next