Skip to content

Serve the shortlink service on Deno Deploy v2 - #10

Open
EthanThatOneKid wants to merge 3 commits into
mainfrom
deploy-v2-handler
Open

EthanThatOneKid wants to merge 3 commits into
mainfrom
deploy-v2-handler

Conversation

@EthanThatOneKid

Copy link
Copy Markdown
Contributor

What

Makes the go.fart.tools shortlink service runnable on the current Deno Deploy platform, which is what the hostname needs before it can come back.

Three changes:

  1. Deploy v2 entrypoint. cli/main.tsx exported nothing, so the new runtime had no handler to serve (the app's only build failed). It now exports default { fetch } through a lazily-initialized router, and keeps the local deno run path behind import.meta.main.
  2. KV is now optional. Deno.openKv() used to run unconditionally at startup, so the process died without a bound database. The service now reads the committed links.json ruleset as its base, merges KV entries when a database is available, and returns 503 from POST/DELETE /api when it is not. Reads and redirects always work.
  3. Versioned ruleset. links.json gains the four shortlinks the live site and blog use — chat, twitter, instagram, in — so the service serves them without any database.

A second commit applies deno fmt to README.md and demo/browser.html; they are unformatted under the current Deno, which makes the Check workflow's format gate fail on any new push.

Verified locally

  • deno fmt --check, deno lint, deno test — clean, 15 tests pass.
  • Ran the service locally against a local KV: GET /api returned the merged ruleset, and /chat, /twitter, /instagram, /in all returned 302 to the expected destinations (the Discord invite, https://x.com/fartlabs_org, https://instagram.com/fartlabs, https://linkedin.com/company/fartlabs).
  • Ran a build with KV forced unavailable to reproduce the deployed (no-database) path: redirects still resolved from links.json, POST /api returned 503 with an explanatory message instead of crashing.

Notes for review

  • The service is deployed to Deno as go-fart-tools; this PR is the repo-side counterpart so the fix lives in git. fart.tools's KV instance limit is 1 on the current plan and it is already taken by worlds-api, so production runs the read-only ruleset until a database can be bound — the write endpoints come back the moment one is.

Goop added 3 commits September 23, 2026 05:39
Export a default fetch handler so the new Deno Deploy runtime can serve the
router, and make the Deno KV layer optional: the service now boots with the
committed links.json ruleset, merges KV entries when a database is bound, and
returns 503 from the write endpoints when it is not. Commit the FartLabs
shortlinks (chat, twitter, instagram, in) so the ruleset is versioned.
The CLI called Deno.openKv() and Deno.serve() at module scope, which made the
service fail to boot on Deno Deploy v2: the platform needs a default export and
no database was bound. Now:

- export a fetch handler so Deno Deploy can serve the app, keeping the
  import.meta.main path for local deno run
- treat Deno KV as an optional overlay on links.json, so the service boots and
  resolves links even when no KV database is assigned (writes answer 503 instead
  of crashing the process)
- answer 404 for paths that do not resolve to a shortlink instead of redirecting
  a request to itself

Also commits the FartLabs shortlinks (chat, in, instagram, twitter) to
links.json so the deployed service resolves them without KV.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant