Spaces:
Sleeping
Sleeping
Download cloudflare-worker.js from ysinghc/pastebin-api: direct link, hf CLI and curl.
- Browser
- Download file 1.05 kB
-
https://huggingface.co/spaces/ysinghc/pastebin-api/resolve/main/cloudflare-worker.js
- Command line
-
hf download hf://spaces/ysinghc/pastebin-api/cloudflare-worker.js
-
curl -L -o cloudflare-worker.js https://huggingface.co/spaces/ysinghc/pastebin-api/resolve/main/cloudflare-worker.js
1.05 kB
| /** | |
| * 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}`); | |
| } | |
| }, | |
| }; | |