Skip to content

Commit ca1858d

Browse files
committed
Add self-ping keep-alive to prevent Render free tier sleep
1 parent b78320c commit ca1858d

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

‎services/api-node/src/index.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,20 @@ server.listen(config.port, () => {
474474
console.log(`CodeAbyss Node API listening on http://localhost:${config.port}`);
475475
});
476476

477+
// Self-ping to prevent Render free tier from sleeping (every 14 minutes)
478+
const RENDER_URL = process.env.RENDER_EXTERNAL_URL;
479+
if (RENDER_URL) {
480+
setInterval(async () => {
481+
try {
482+
const res = await fetch(`${RENDER_URL}/api/health`);
483+
console.log(`[keep-alive] pinged ${RENDER_URL} → ${res.status}`);
484+
} catch (e) {
485+
console.log(`[keep-alive] ping failed: ${(e as Error).message}`);
486+
}
487+
}, 14 * 60 * 1000); // 14 minutes
488+
console.log("[keep-alive] self-ping enabled (every 14 min)");
489+
}
490+
477491
// Graceful shutdown
478492
function shutdown() {
479493
console.log("Shutting down gracefully...");

0 commit comments

Comments
 (0)