Skip to content

unionlabs/worker-url-shortener

Repository files navigation

URL Shortener - Cloudflare Worker

Development

Prerequisites

You have two options:

Option one (recommended):

  • install devenv && run devenv up
  • done.

Now you can run dev, fmt, etc. (tasks are defined in tasks.nix)

Option two: follow Cloudflare's guide

Note

the rest of the guide assumes you're using devenv

if you're installing stuff manully, take a look at tasks.nix for the commands

Once you've installed the prerequisites, you can run:

dev server

dev

rowser-based sqlite viewer

d1-viewer

seed local d1 database with data

d1-seed

shorten a URL

curl --url http://localhost:8787/create \
  --request 'POST' \
  --data-binary 'https://docs.union.build/reference/graphql/?query=%7B%20__typename%20%7D'

now refresh the d1 viewer page and you should see the new record

Usage

Note

When running locally use http://localhost:8787

Shorten a URL

curl --url http://localhost:8787/create \
  --request 'POST' \
  --data-binary 'https://docs.union.build/reference/graphql/?query=%7B%20__typename%20%7D'

This will return a short the shortened URL, for example:

# example
https://localhost/26

Expand a short URL

curl --url http://localhost:8787/26