/** * 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}`); } }, };