Skip to content

a1fredbao/clipboard

Repository files navigation

πŸ“‹ Clipboard

A lightweight, shareable online clipboard built on Cloudflare Workers + KV β€” no accounts, no fuss. Just visit a URL, paste your text, and share the link.

Cloudflare Workers Hono React Vite TypeScript License: MIT


Features

  • Instant sharing β€” every clipboard lives at https://<your-worker>.workers.dev/<key>
  • Auto-generated keys β€” visiting the root / redirects you to a fresh random key
  • Persistent storage β€” content is backed by Cloudflare KV, globally distributed
  • Zero infrastructure β€” runs entirely on Cloudflare's edge network, no servers to manage
  • React SPA β€” fast, responsive frontend served as static assets

Project Structure

clipboard/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts          # Hono worker β€” API routes (GET /api/:key, PUT /api/:key)
β”‚   └── client/
β”‚       β”œβ”€β”€ main.tsx      # React app entry point
β”‚       β”œβ”€β”€ App.tsx       # Main clipboard component (key routing, editor, save)
β”‚       └── index.css     # Styles
β”œβ”€β”€ index.html            # Vite HTML shell
β”œβ”€β”€ wrangler.jsonc        # Cloudflare Workers config (KV bindings, assets)
β”œβ”€β”€ vite.config.ts        # Vite + Cloudflare plugin config
β”œβ”€β”€ tsconfig.json
└── package.json

How it works

Browser (React SPA)
      β”‚
      β”‚  GET  /api/:key   β†’  read from KV
      β”‚  PUT  /api/:key   β†’  write to KV
      β–Ό
Hono Worker (src/index.ts)
      β”‚
      β–Ό
Cloudflare KV (CLIPBOARD_KV binding)

Static assets (dist/client/) are served directly by Cloudflare's asset pipeline β€” the Worker only handles /api/* requests.


Deployment

Prerequisites

Tool Version Install
Node.js >= 18 nodejs.org
npm >= 9 bundled with Node
Wrangler CLI >= 4 npm install -g wrangler
Cloudflare account β€” dash.cloudflare.com

Step 1 β€” Authenticate Wrangler

wrangler login

This opens a browser window to authorise Wrangler against your Cloudflare account.


Step 2 β€” Create the KV Namespace

Cloudflare KV requires you to create namespaces before you can use them.

# Production namespace
wrangler kv namespace create CLIPBOARD_KV

# Preview namespace (used by `wrangler dev`)
wrangler kv namespace create CLIPBOARD_KV --preview

Each command prints an id. Copy both IDs into wrangler.jsonc:

// wrangler.jsonc
"kv_namespaces": [
  {
    "binding": "CLIPBOARD_KV",
    "id":         "<paste production id here>",
    "preview_id": "<paste preview id here>"
  }
]

Step 3 β€” Install Dependencies

npm install

Step 4 β€” (Optional) Regenerate TypeScript Types

Wrangler can auto-generate a worker-configuration.d.ts file that gives you full type-safety for your bindings:

npm run cf-typegen

Step 5 β€” Local Development

npm run dev

Vite starts a local dev server (typically at http://localhost:5173). The @cloudflare/vite-plugin emulates Workers bindings locally β€” your KV reads/writes hit the preview namespace in real Cloudflare KV.


Step 6 β€” Deploy to Cloudflare Workers

npm run deploy

This runs vite build (outputs to dist/) followed by wrangler deploy. Wrangler uploads:

  • Worker script (src/index.ts, bundled)
  • Static assets (dist/client/) β€” served by Cloudflare's asset pipeline

Your clipboard is now live at:

https://clipboard.<your-account>.workers.dev

Tip: To use a custom domain, add a route or custom domain in the Cloudflare dashboard under Workers & Pages β†’ your worker β†’ Settings β†’ Domains & Routes.


Updating an existing deployment

Simply re-run:

npm run deploy

Wrangler performs an atomic deployment β€” the new version is live instantly with zero downtime.


Configuration Reference

Field File Description
name wrangler.jsonc Worker name (also the default subdomain)
compatibility_date wrangler.jsonc Pins the Workers runtime version
kv_namespaces[].id wrangler.jsonc Production KV namespace ID
kv_namespaces[].preview_id wrangler.jsonc Dev/preview KV namespace ID
assets.directory wrangler.jsonc Output dir for the built React SPA

References


License

MIT

About

A simple online clipboard based on cloudflare workers. Self-hosted. No security concerns.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors