Konami
Note thisNovember 12, 2025 - 1 day(s) ago

I wanted to add a notes thing to my site. You know, like those sticky notes pages where people can leave random thoughts. I thought it'd be cool, so I built it. I've been messing around with Workers, D1, and the entire Cloudflare stack for a while, so why not make something stupid.

Problem is my site is static. Next.js, builds everything at build time, no backend, no database, nothing. So I needed backend stuff without actually having a backend.

Cloudflare Workers to the rescue. I'm already using Cloudflare Pages, so Workers made sense. They're fast, free tier is generous, and they play nice with Cloudflare's other stuff. They're not sponsoring me I just dig them.

I went with Workers for the API, D1 for the database, KV for sessions, and GitHub OAuth for auth. All free, all simple. No server to manage, no database to provision, just write code and deploy.

D1 is Cloudflare's SQLite thing. Edge distributed, so it's fast. The schema is stupid simple:

CREATE TABLE IF NOT EXISTS notes (
  id TEXT PRIMARY KEY,
  user_id INTEGER NOT NULL,
  content TEXT NOT NULL,
  created_at TEXT NOT NULL
);

Four columns. That's it. Added some indexes for faster queries, but that's the whole thing.

I used Hono for the worker and it does three things: handles GitHub OAuth, does notes CRUD, and manages sessions.

OAuth flow is pretty straightforward. User clicks sign in, goes to GitHub, GitHub sends them back with a code, worker exchanges code for token, gets user info, creates session, stores it in KV, sends user back to frontend with token in URL. Sessions expire after 7 days, user data is cached for 30 days so we don't hit GitHub's API every time.

The page uses SWR on a client component because it needs auth state and interactions. Notes show up in a grid with random rotations and colors. Shows content, GitHub avatar and username, timestamp. Users can post if logged in, delete their own notes. I can delete any note because I'm the admin because most of y'all suck.

Infinite scroll pagination. Scroll near bottom, loads more notes. Ide gas.

I added some limits: max 500 chars per note, max 3 notes per user (oldest gets deleted when you post a 4th), and notes are public. Keeps it simple and prevents spam. If someone wants to spam, they can only do 3 notes max, and I can delete them.

D1 is pretty cool. It's SQLite, so if you know SQL you're good. API is straightforward, queries are fast. KV is perfect for sessions. Fast, TTL built in, free. Storing sessions and user data there, works great.

Whole thing took 25 minutes. There was no hard part. Yes, this blog post is boring.

Worker code is in a separate folder in my repo. Simple Hono app with routes for auth and notes. Frontend just calls the worker API and displays results.

If you want to see it, check out the notes page. Bye.