• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
halffullheart

halffullheart

heartbeat

Public
Like
heartbeat
Home
Code
7
README.md
client.js
generate-vapid-keys.ts
index.html
H
main.ts
C
monitor.ts
sw.js
Environment variables
3
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
README.md

🖥️ Home Server Monitor

A serverless monitoring solution for your home server with push notifications when it goes offline.

Features

  • Real-time Status: Check if your server is online/offline
  • Push Notifications: Get notified when server goes down (1+ hour without heartbeat)
  • PWA Support: Install as a Progressive Web App on mobile/desktop
  • Clean Architecture: Static files served separately for better maintainability

Project Structure

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

Setup

1. Generate VAPID Keys (for push notifications)

Run the generate-vapid-keys.ts script to generate your VAPID keys.

2. Set Environment Variables

Add these to your Val Town environment:

  • VAPID_PUBLIC_KEY - Public key from step 1
  • VAPID_PRIVATE_KEY - Private key from step 1

3. Configure Your Server

Add a cron job to your home server that pings the heartbeat endpoint every 15 minutes:

*/15 * * * * curl -X POST https://halffullheartbeat.val.run/heartbeat

4. Enable Notifications

  1. Visit your deployed app
  2. Click "Enable Notifications"
  3. Grant notification permission

API Endpoints

POST /heartbeat

Your server calls this endpoint to signal it's alive.

GET /status

Returns current server status:

{ "lastHeartbeat": 1234567890000, "isOnline": true, "minutesSince": 5, "currentTime": 1234567890000 }

POST /subscribe

Subscribe to push notifications (called by frontend).

GET /vapid-public-key

Get VAPID public key for push subscription.

How It Works

  1. Heartbeat: Your server sends a POST request every 15 minutes to /heartbeat
  2. Monitoring: The monitor.ts interval val checks every 15 minutes if any heartbeat was received in the last hour
  3. Notifications: If server is down (no heartbeat for 1+ hour), push notifications are sent to all subscribers
  4. Status: Frontend polls /status every 30 seconds to show real-time status

Architecture Improvements

This project now uses a clean separation of concerns:

  • main.ts: Pure backend logic with Hono routes
  • index.html: Static HTML served as-is (no React SSR needed)
  • client.js: Frontend JavaScript in a separate file
  • sw.js: Service Worker logic in its own file

Benefits:

  • ✅ Better maintainability
  • ✅ Easier debugging (proper file names in dev tools)
  • ✅ Better caching (static files cached separately)
  • ✅ No need for React imports or dangerouslySetInnerHTML
  • ✅ Cleaner codebase

Technologies

  • Val Town: Serverless hosting
  • Hono: Fast web framework
  • SQLite: Database for heartbeats and subscriptions
  • Push API: Browser push notifications
  • Service Workers: Offline support and notifications
Code
README.mdclient.jsgenerate-vapid-keys.tsindex.html
H
main.ts
C
monitor.ts
sw.js
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.