Public
Like
like-anything
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.
Viewing readonly version of main branch: v13View latest version
A cross-origin API service that tracks likes across multiple websites.
- Records likes for websites and specific pages
- Supports multiple websites from a single API
- Returns updated like counts for real-time UI updates
- CORS enabled for cross-origin requests
Record a like for a website/page:
{ "website": "example.com", "pageUrl": "/blog/my-post" // optional }
Returns: { "success": true, "website": "example.com", "pageUrl": "/blog/my-post", "likeCount": 42 }
Get like count for a specific website. Add ?pageUrl=/path for specific pages.
Get all like data for admin/stats purposes.
backend/- Server-side codedatabase.ts- SQLite database setup and queries for likes tracking
index.ts- Main HTTP handler using Hono with CORS support
// Record a like from your website
fetch('https://your-val-url.val.run/api/like', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
website: 'mysite.com',
pageUrl: window.location.pathname
})
})
.then(res => res.json())
.then(data => {
// Update your UI with data.likeCount
document.getElementById('like-count').textContent = data.likeCount;
});