File size: 1,050 Bytes
d24b0ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
/**
 * Cloudflare Worker to keep the Pastebin API awake on Hugging Face.
 * This worker pings the /health endpoint of the API.
 *
 * Setup Instructions:
 * 1. Create a new Worker in the Cloudflare Dashboard.
 * 2. Paste this code into the editor.
 * 3. Go to 'Triggers' -> 'Cron Triggers'.
 * 4. Add a trigger for "Every Day" (e.g., `0 0 * * *`) or any interval under 48 hours.
 */

export default {
  async scheduled(event, env, ctx) {
    const TARGET_URL = "https://ysinghc-pastebin-api.hf.space/health";

    console.log(`Pinging keep-alive endpoint: ${TARGET_URL}`);

    try {
      const response = await fetch(TARGET_URL, {
        method: 'GET',
        headers: {
          'User-Agent': 'Cloudflare-KeepAlive-Worker',
        },
      });

      if (response.ok) {
        console.log(`Successfully pinged API. Status: ${response.status}`);
      } else {
        console.error(`API responded with error. Status: ${response.status}`);
      }
    } catch (error) {
      console.error(`Error pinging API: ${error.message}`);
    }
  },
};