Wisp is a URL shortener written in Go and deployed to Cloudflare Workers as WebAssembly. It focuses on staying small, fast, and cheap β everything runs on the Cloudflare Workers Free plan.
π Live: wisp.pyr33x.top
- β‘ Edge: Three Go Workers compiled with TinyGo, built and deployed by goflare β no Node.js, no Wrangler
- ποΈ Storage: Each service owns its own D1 database, no shared tables
- π Codes: 7-character base62 codes from a cryptographically secure source, collisions retried on the
UNIQUEconstraint - π Analytics: Click counting with a single atomic upsert per redirect
- π‘οΈ Abuse protection: Per-IP rate limiting on link creation, URL validation, redirect-loop detection
- π Internal auth: Internal Workers reject any request without the shared
X-Wisp-Internalsecret - π₯οΈ Web UI: Shorten, copy, look up clicks and keep a recent-links list at wisp.pyr33x.top, served by the gateway itself
- πͺΆ Small: ~225β265 KiB of wasm per Worker (~75β95 KiB gzipped)
G=https://wisp.pyr33x.top
# shorten
curl -s -X POST $G/api/links -H 'Content-Type: application/json' -d '{"url":"https://github.com/Pyr33x/wisp"}'
# {"code":"ubRE08P","short_url":"https://wisp.pyr33x.top/ubRE08P","origin":"https://github.com/Pyr33x/wisp","created_at":1794725854373}
# follow (302 β origin)
curl -s -o /dev/null -D - $G/ubRE08P
# stats
curl -s $G/api/links/ubRE08P/stats
# {"code":"ubRE08P","clicks":1}client ββ> wisp-gateway (wisp.pyr33x.top) ββHTTP + X-Wisp-Internalββ> wisp-link (workers.dev) ββ D1 wisp-links
β ββββββββββββββββββββββ> wisp-analytics (workers.dev) ββ D1 wisp-analytics
βββ D1 wisp-gateway (rate limits)
| Worker | Visibility | Owns | Role |
|---|---|---|---|
wisp-gateway |
public (custom domain) | wisp-gateway D1 (rate limits) |
Validates input, rate-limits, checks the admin token, orchestrates the other two |
wisp-link |
internal (workers.dev + secret) | wisp-links D1 |
Creates, resolves and soft-deletes links; builds short URLs |
wisp-analytics |
internal (workers.dev + secret) | wisp-analytics D1 |
Records clicks and returns counts |
All cross-service traffic is HTTP and flows through the gateway β link and analytics never call each other.
Cloudflare blocks a Worker from fetching another Worker on the same zone (error 1042, which surfaces as a bare 404). With every Worker on workers.dev, the gateway's internal calls never arrive. Serving the gateway on its own zone (wisp.pyr33x.top) while link and analytics stay on workers.dev makes every call cross zones, which is allowed.
goflare cannot declare service bindings yet. The transport already switches to them automatically if a LINK / ANALYTICS binding ever appears, so moving off public URLs is a config change.
git clone https://github.com/pyr33x/wisp.git
cd wisp
go install webtyp.com/goflare/cmd/goflare@v0.5.69
go install webtyp.com/devflow/cmd/gotest@v0.4.191TinyGo 0.41 supports Go up to 1.26;
go.modpinsgo 1.26.8. Rungoflare tinygoto install TinyGo. goflare v0.5.69 embedswebtyp.com/cloudflarev0.0.73 β keep both pinned together, goflare refuses to build on version skew.
| Method | Path | Description | Responses |
|---|---|---|---|
GET |
/ |
Web UI | 200 |
POST |
/api/links |
Create a short link from {"url": "..."} |
201, 400, 429, 502 |
GET |
/{code} |
Redirect to the original URL and count the click | 302, 404, 502 |
GET |
/api/links/{code}/stats |
Click count for a link | 200, 404, 502 |
DELETE |
/api/links/{code} |
Soft-delete a link (Authorization: Bearer <ADMIN_TOKEN>) |
204, 401, 502 |
Redirects are always 302 with Cache-Control: private, max-age=0 β never 301, so browsers can't cache them and skip the click count.
All errors share one shape:
{"error": {"code": "rate_limited", "message": "too many links created, try again later"}}| Status | Meaning |
|---|---|
400 |
Invalid input (invalid_json, invalid_url, url_too_long, unsupported_scheme, missing_host, redirect_loop) |
401 |
Missing or wrong admin token / internal secret |
404 |
Unknown or deleted link |
429 |
Rate limited, see Retry-After |
502 |
A downstream Worker failed (details are logged, never returned) |
Each Worker lives in services/<name>/ and has its own .env.example.
| Variable | Worker | Description | Kind |
|---|---|---|---|
BASE_URL |
gateway, link | Public gateway origin; short URLs are BASE_URL/code |
var |
LINK_URL |
gateway | workers.dev origin of wisp-link |
var |
ANALYTICS_URL |
gateway | workers.dev origin of wisp-analytics |
var |
INTERNAL_SECRET |
all | Shared secret for internal calls | Worker secret |
ADMIN_TOKEN |
gateway | Bearer token for DELETE |
Worker secret |
D1_NAME / D1_BINDING |
all | D1 database name and binding (DB) |
goflare config |
DOMAIN |
gateway | Custom domain the gateway is served on | goflare config |
Worker secrets must be type Secret in the dashboard β goflare replaces plain-text and JSON variables on every deploy.
- 10 creates per minute per IP, keyed on
CF-Connecting-IP - Exceeding it returns
429withRetry-After - If the rate-limit store fails, requests are allowed and the failure is logged
- For flood protection on top, add a Cloudflare rate limiting rule for the gateway's hostname (Security β WAF β Rate limiting rules), e.g. 100 requests / 10 s per IP
gotestRuns go vet, staticcheck, go test -race with coverage, and the //go:build wasm suite in headless Chrome.
| Suite | Covers |
|---|---|
Native (tests/) |
Code generation and bias, URL validation, BASE_URL joining, constant-time compare, every handler of all three services through a router that enforces the real gate and middleware order, SQL statements, rate-limit windows, fail-open, transport timeouts |
Wasm (tests/edge_wasm_test.go) |
The real webtyp.com/cloudflare stack (d1.NewEdge, env, edge router) against a fake context.env and a fake D1 that speaks the D1 JS API, crypto.getRandomValues, transport selection, and a regression test that fetch is never called with goflare's global Proxy as this |
G=https://wisp.pyr33x.top
curl -s -X POST $G/api/links -d '{"url":"ftp://example.org"}' # 400 unsupported_scheme
curl -s -X POST $G/api/links -d "{\"url\":\"$G/abc\"}" # 400 redirect_loop
curl -s $G/zzzzzzz # 404 not_found
curl -s -X DELETE $G/api/links/zzzzzzz # 401 unauthorized
curl -s https://wisp-link.<subdomain>.workers.dev/api/links/zzzzzzz # 401, internal Workers need the secret
for i in $(seq 1 11); do curl -s -o /dev/null -w "%{http_code} " -X POST $G/api/links -d '{"url":"https://example.org"}'; done # ... 429goflare builds web/edge/main.go from the working directory, so stage a Worker at the root first:
cp -R services/link/web web
PROJECT_NAME=wisp-link WORKER_NAME=wisp-link goflare build -env /dev/null
goflare size -env /dev/null
rm -rf webDeploys run in GitHub Actions with webtyp/goflare@v0.5.69, one workflow per Worker, triggered on pushes to master that touch that Worker or the code it compiles in. Every deploy runs the full CI first, then migrates its D1 database via go run ./cmd/migrate -service <name>, then uploads.
- Secrets:
CLOUDFLARE_API_TOKEN,CLOUDFLARE_ACCOUNT_ID - Variables:
WISP_BASE_URL,WISP_LINK_URL,WISP_ANALYTICS_URL - Optional variable
WISP_DOMAIN: set it for one gateway deploy to attach the custom domain, then delete it. While it is set, goflare also manages a zone rate-limit rule, and that step fails with account-owned (cfat_β¦) tokens
- Add a domain to the account and pick the gateway hostname (e.g.
wisp.pyr33x.top) - Create D1 databases
wisp-links,wisp-analytics,wisp-gateway - Create an API token with:
- Account: Workers Scripts Edit, D1 Edit
- Zone (your domain), only while
WISP_DOMAINis set: Zone Read, Workers Routes Edit, Zone WAF Edit
- Create the three Workers and add their secrets (
INTERNAL_SECRETon all,ADMIN_TOKENon the gateway) before the first deploy - Keep workers.dev enabled on
wisp-linkandwisp-analytics; never put them on the gateway's domain - Deploy link and analytics before the gateway; with
WISP_DOMAINset, the gateway deploy attaches the domain (or add it once under the Worker's Settings β Domains & Routes)
| Symptom | Cause |
|---|---|
error code: 1101 on every request |
The Worker's main() stopped at startup β a missing secret or variable; the Worker logs name it |
Gateway returns 502, link logs show nothing |
Gateway is on the same zone as link/analytics (1042); serve it from a custom domain |
webtyp/cloudflare version skew |
go.mod and the goflare action drifted apart; keep v0.0.73 β v0.5.69 |
rate limit: β¦ HTTP 403 at the end of a gateway deploy |
goflare's zone rate-limit step, which rejects account-owned tokens; the Worker is already live. Delete WISP_DOMAIN once the domain is attached |
Feel free to open issues or submit pull requests. Any help is appreciated!
MIT @ Mehdi Parandak
