I Added Like and Dislike Buttons to My Static Blog Using Cloudflare Workers and D1
Table of Contents▼
My blog is a Next.js and MDX setup, which basically means it is just files. There is no backend, no database, no server running anywhere. It is fast and simple and I love it that way. But I always wanted to know what my readers actually think about my posts. So I decided to add like and dislike buttons. The problem was, where do I even store that data when I have no backend?
That is when I looked at Cloudflare. I already had my domains on Cloudflare so I figured I would just use what they already offer. They have something called a Cloudflare Worker, which is basically a tiny function that runs on their servers and responds to requests. And they have D1, which is a lightweight SQL database that lives right next to the worker. I created a database with one table called reactions, with columns for the post slug, title, likes, and dislikes. The whole schema was maybe four lines of SQL.
Then I wrote the worker. It handles two things, a GET request that returns the current like and dislike count for a post, and a POST request that increments either the like or dislike count when someone clicks a button. I pointed a custom subdomain of my domain to the worker so it feels clean and professional. Setting it up took maybe twenty minutes, all done directly on the Cloudflare dashboard without touching a terminal.
On the blog side I created a simple React component called Reactions. It fetches the current counts when the page loads and sends a POST request when someone clicks like or dislike. The worker URL is stored in an environment variable so it is easy to update later. I placed the component right next to the share buttons on each blog post so it feels natural and fits the existing design.
For the dashboard I created a separate Next.js app deployed on its own subdomain. It has a simple login page protected by a username and password stored in environment variables. Once logged in I can see every post, its title, and exactly how many likes and dislikes it has. The whole thing, from zero to a working like system with a live dashboard, took an afternoon. If I can do it with a frontend only blog and no backend experience, honestly anyone can.