A serverless monitoring solution for your home server with push notifications when it goes offline.
heartbeat/
āāā main.ts # Hono server with API routes
āāā index.html # Static HTML page
āāā client.js # Frontend JavaScript
āāā sw.js # Service Worker for push notifications
āāā monitor.ts # Interval val that checks for downtime
āāā generate-vapid-keys.ts # Script to generate VAPID keys
āāā README.md # This file
Run the generate-vapid-keys.ts script to generate your VAPID keys.
Add these to your Val Town environment:
VAPID_PUBLIC_KEY - Public key from step 1VAPID_PRIVATE_KEY - Private key from step 1Add a cron job to your home server that pings the heartbeat endpoint every 15 minutes:
*/15 * * * * curl -X POST https://halffullheartbeat.val.run/heartbeat
Your server calls this endpoint to signal it's alive.
Returns current server status:
{ "lastHeartbeat": 1234567890000, "isOnline": true, "minutesSince": 5, "currentTime": 1234567890000 }
Subscribe to push notifications (called by frontend).
Get VAPID public key for push subscription.
/heartbeatmonitor.ts interval val checks every 15 minutes if any heartbeat was received in the last hour/status every 30 seconds to show real-time statusThis project now uses a clean separation of concerns:
Benefits: