Skip to content

About

URL Shortener

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Shortener

URL Shortener built as a single Cloudflare Worker with analytics and caching.

Setup

pnpm install

Create the D1 database and KV namespace and update wrangler.jsonc:

pnpm dlx wrangler d1 create shortener-db
pnpm dlx wrangler kv namespace create LINKS_CACHE

Apply the schema:

pnpm run db:migrate:local   # Local
pnpm run db:migrate:remote  # Production

Set the secret:

# Local
cp .dev.vars.example .dev.vars

# Production
pnpm dlx wrangler secret put SECRET

Development

pnpm run dev
pnpm run typecheck
pnpm run tail        # Stream logs from the deployed worker

Deploy

pnpm run deploy

Configuration

Set in wrangler.jsonc under vars:

  • SITE_URL Where GET / redirects to.
  • ALLOWED_ORIGIN Origin allowed to call /api/* (use * for any origin).
  • SHORT_URL URL used to build the shortUrl field.

About

URL Shortener

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages