This is a simple pastebin service implemented as a Cloudflare Worker using Hono framework. It supports storing text content in R2 bucket storage with API endpoints for creating, retrieving and managing pastes.
- Upload paste snippets (text files)
- Retrieve paste by ID
- View paste with syntax highlighting
- Delete paste functionality
- List all pastes
- Paste information endpoint
- Automatic expiry (48 hours by default, configurable per paste)
- Web UI for easy access
This project works as a Nix package:
- Enter development shell:
cd ~/Documents/git/pastebin-r2
nix develop- Build the project:
yarn build- Run in development mode:
yarn dev- Deploy to Cloudflare Workers:
yarn deployBuild using Nix directly without entering shell:
nix build .#packages.defaultsrc/index.ts- Main application code with API routesdist/- Build outputs including bundled JavaScript and HTML fileswrangler.toml- Cloudflare Workers configurationpackage.json- Dependencies and scriptstsconfig.json- TypeScript configuration
Pastes expire automatically. The lifetime is stamped into the object's custom
metadata when it is written, enforced on every read, and an hourly cron trigger
([triggers] in wrangler.toml) sweeps expired objects out of the bucket.
The default and the maximum are both 48 hours. A shorter lifetime can be
requested with the ttl query parameter (or the X-Expires-In header) on
create/update, as plain seconds or with an s/m/h/d suffix. Values above
48 hours are clamped down, and the minimum is 60 seconds.
curl --data-binary @- 'https://example.com/?ttl=2h' < file.txt
curl -H 'X-Expires-In: 900' --data-binary @- https://example.com < file.txtPOST /- Create new paste, returns URL with ID (?ttl=sets lifetime)GET /:id- Retrieve paste by IDPOST /:id- Update paste content (?ttl=sets lifetime)DELETE /:id- Delete pasteGET /list- List all paste IDsGET /info/:id- Get metadata about paste, including itsexpirestimeGET /:id/highlight- View with syntax highlightingGET /text/:id- Get text content