-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpinger.js
More file actions
42 lines (35 loc) · 1.04 KB
/
pinger.js
File metadata and controls
42 lines (35 loc) · 1.04 KB
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
40
41
export default {
// List URLs here directly
urlsToPing: [
"https://example1.com",
"https://example2.com",
// Add more URLs as needed
],
async scheduled(event, env, ctx) {
if (this.urlsToPing.length === 0) {
console.log('No URLs configured to ping');
return;
}
const pingPromises = this.urlsToPing.map(async (url) => {
try {
const response = await fetch(url);
console.log(`Pinged ${url}: ${response.status}`);
} catch (error) {
console.error(`Failed to ping ${url}:`, error.message);
}
});
await Promise.all(pingPromises);
},
async fetch(request, env, ctx) {
const url = new URL(request.url);
if (url.pathname === "/") {
return new Response(
this.urlsToPing.length > 0
? `Currently configured URLs to ping:\n\n${this.urlsToPing.join("\n")}`
: "No URLs configured to ping",
{ status: 200, headers: { "Content-Type": "text/plain" } }
);
}
return new Response("Not Found", { status: 404 });
}
};