Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Serble Link Shortener

A very simple Cloudflare Worker link shortener that lets you choose a custom name.

  • GET / — serves the HTML form (with a random 10-char name pre-filled)
  • GET /<name> — looks <name> up in KV and 308-redirects to the target
  • POST / — form-encoded name + location, creates a short link

Layout

Path What
src/index.js The whole Worker
src/icon.svg The logo, for reuse elsewhere (not served)
wrangler.jsonc Worker name, entrypoint, KV binding
package.json Scripts + wrangler dev dependency

Local development

npm install
npm run dev        # http://localhost:8787

wrangler dev runs the Worker locally against a local KV store kept in .wrangler/state/ — it is completely separate from production data, starts empty, and is gitignored. Create a link through the form at http://localhost:8787, or seed one directly:

npx wrangler kv key put --local --binding=linkstorage test serble.net
npx wrangler kv key list --local --binding=linkstorage
curl -si localhost:8787/test        # -> 308 to https://serble.net

Creating links needs Turnstile. .dev.vars (gitignored) holds Cloudflare's public test keys so local dev always passes:

TURNSTILE_SITEKEY=1x00000000000000000000AA
TURNSTILE_SECRET=1x0000000000000000000000000000000AA

To run locally against real production KV instead, use npx wrangler dev --remote. Reads are harmless; be aware that any POST in remote mode writes real short links.

Deployment

Deploys are automatic. The Worker is connected to this repo via Workers Builds in the Cloudflare dashboard - pushing to the default branch builds and deploys it. Watch a build under the Worker's Deployments tab.

Set the Turnstile keys before the first push. Creation fails closed, so until both are in place POST / returns 503 and the form cannot make links. Redirects are unaffected.

Both live in the Cloudflare dashboard (Worker → Settings → Variables): TURNSTILE_SITEKEY as a plaintext variable, TURNSTILE_SECRET as a secret. wrangler.jsonc sets keep_vars so deploys leave them alone.

To deploy by hand (normally unnecessary): npm run deploy. Live logs: npm run tail.

About

Cloudflare Worker based link shortener

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages