Skip to content

jfalava/link-shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Link Shortener

KV database studies and proofs of concept

My implementation: "JFA Link Shortener" Terms of Use

Requirements

  • A KV-like NoSQL database, like AWS DynamoDB or Cloudflare KV
  • A serverless functions provider, like AWS Lambda or Cloudflare Workers
  • A way to interact with the API, like cURL or a frontend UI of any kind

How it works

How to deploy

Cloudflare

Prerequisites

  • Cloudflare account with Workers enabled
  • Wrangler CLI (npm install -g wrangler)
  • Two KV namespaces created in Cloudflare:
    • One for URL storage
    • One for rate limiting

Steps

  1. Clone and set up:
$ git clone https://github.com/jfalava/link-shortener.git
$ cd link-shortener/cloudflare
$ npm install -g pnpm
$ pnpm install
  1. Create KV namespaces in Cloudflare dashboard or via the wrangler cli:
$ pnpx wrangler kv:namespace create "URL_STORAGE"
$ pnpx wrangler kv:namespace create "RATE_LIMIT"
  1. Configure wrangler.toml:
name = "<your project name>"
main = "src/index.ts"
compatibility_date = "2025-01-29"
compatibility_flags = ["nodejs_compat"]
routes = [{ pattern = "<your-domain>", custom_domain = true }]

[observability]
enabled = true

[placement]
mode = "smart"

[[kv_namespaces]]
binding = "URL_STORAGE"
id = "<URL_STORAGE id>"

[[kv_namespaces]]
binding = "RATE_LIMIT"
id = "<RATE_LIMIT id>"
  1. Deploy to Cloudflare:
$ pnpm run deploy

After deployment, your worker will be available at your-worker.your-subdomain.workers.dev

TODO

  • AWS Lambda version of the API endpoint
  • IBM Cloud Functions version of the API endpoint
  • Self-hosted version of the code and the infrastructure required
  • IaaC deployments for AWS and IBM Cloud