Skip to content
baskingspotPublic

About

The router for baskingspot.dev, the Zig download mirror, and the Terraform that gives each library its own Worker.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

site

The router for baskingspot.dev, the Zig download mirror, and the Terraform that gives each library its own Worker.

baskingspot.dev/stdx/ is stdx's docs. Each library repo builds its docs into a folder named for its slug and deploys them to a private Cloudflare Worker, baskingspot-dev-stdx. That Worker has no public URL. The router in this repo sends /stdx/... to the stdx Worker through a service binding and serves the landing page itself. The router and the Zig mirror are the public Workers. It doesn't strip the prefix, so a library's own redirects, like /stdx/api to /stdx/api/, stay inside it.

Layout

Path Content
sites.json The roster: each slug, the repo that deploys it, and a one-sentence description for the landing page
router/ The router Worker and its wrangler.jsonc. index.html and static/ are the landing page. build.mjs writes public/ from them and sites.json
mirror/ The Zig download Worker at zig.baskingspot.dev, and its tests
terraform/ For each site, the router, and the mirror: an empty Worker, a token scoped to it, and the token written into the repo's secrets
terraform/tests/ Tests with mocked providers. They check the wiring: one token per Worker, scoped to its id

The router's wrangler.jsonc lists one service binding per site it serves, named SITE_<SLUG>.

The router also adds security headers to every site's responses, and replaces any 404 with the branded page. The front page gets its headers from router/static/_headers. just build writes sitemap.xml from the roster and security.txt, whose Expires is a year past the build. The zone's own settings (HTTPS only, HSTS, TLS 1.2, mail records) are Terraform in ~/code/cloudflare, not here.

Markdown for agents

Every page has a markdown copy at the same path, with index.md in place of the trailing slash. /stdx/ is /stdx/index.md. A library's docs build writes the copy from the markdown the site is generated from, so it is the source, not a conversion of the HTML.

The router does three things with that:

  • A request with Accept: text/markdown gets the copy, sent as text/markdown. When the copy is missing, the router serves the HTML page instead of a 404.
  • Every response advertises the copy with Link: </stdx/index.md>; rel="alternate"; type="text/markdown", and the index at /llms.txt with rel="describedby". It also sets Vary: Accept, so a cache keeps the two apart, and marks the markdown noindex so it does not compete with the page.
  • The front page is an asset, and assets answer before the Worker runs. run_worker_first in wrangler.jsonc names /, so the front page negotiates too.

just build writes /llms.txt from sites.json in the llmstxt.org v2 format, and the front page's own copy at /index.md.

Install URLs

/<slug>/<tag>.tar.gz is the install URL for a release, where the tag is semver shaped: v0.1.0.tar.gz, v0.2.0-rc.1.tar.gz, v1.0.0+build.5.tar.gz. GitHub's .zip archive is served too. A branch, latest, or any other tag shape is not a version path; use GitHub for those.

The extension is part of the URL on purpose: tools such as zon2nix decide how to unpack a package from the URL's extension. .tar.gz is the documented form.

The Worker asks GitHub for the documented archive URL and passes on the codeload.github.com location GitHub returns, so the client follows one redirect instead of two. Nothing is validated: a tag that does not exist 404s at codeload, the same as when it is fetched from GitHub directly. A network failure or an unexpected answer falls back to the documented archive URL.

The install command is therefore short and stable:

zig fetch --save https://baskingspot.dev/cli/v0.1.0.tar.gz

A version path without an extension is a 308 to the .tar.gz form, and one with a trailing slash is a 308 to the form without it. That keeps the rule simple: a trailing slash is the docs site, no trailing slash is a machine endpoint. The router only answers a slug that has a service binding, so a repo that is not registered is a 404. It serves source archives only: a program's binaries are the release assets on GitHub, and the package-manager channels built on them. Do not add a route that mirrors them.

Zig downloads

zig.baskingspot.dev/<file> serves a Zig tarball or its .minisig. It is a pull-through cache: a hit comes from Cloudflare's edge cache, and a miss takes the file from a random community mirror, then another, and ends at ziglang.org. The name decides the origin path: a release is /download/<version>/<file> and a -dev. build is /builds/<file>, which is the rule in MIRRORS.md. A name that is not a Zig tarball is a 404. An upstream that will not answer is a 504, so the client knows the problem is not here.

The mirror verifies nothing. The Zig Software Foundation signs every tarball and the client checks the signature, so a mirror is not a trust anchor. That is also why there is no R2 bucket behind this: an evicted object is a miss, and a miss is allowed to pull from the origin again.

mirror/ has its own Worker and its own token, so a bad deploy cannot take the docs down.

Add a site

  1. Add the slug, its repo, its kind, and a one-sentence description to sites.json: "stdx": { "repo": "stdx", "kind": "library", "description": "..." }. kind is library or tool, and picks the landing page column. The description is the entry on the page, and an unknown kind fails the build.
  2. Run just plan, read it, and run just apply. It creates the Worker baskingspot-dev-<slug>, a token that can deploy only that Worker, and sets CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID in the repo.
  3. In the library repo, deploy the Worker with wrangler deploy, using the secret from step 2.
  4. In this repo, add the matching binding to router/wrangler.jsonc and push. CI deploys the router.

The router can't bind a Worker that has no deployed version, which is why step 4 comes after step 3.

Work on it

nix develop provides OpenTofu, wrangler, and the linters, and direnv allow loads them. Copy .envrc.local.example to .envrc.local and set the two tokens. just lists the recipes, and just ci runs the tests and the lint.

Only a person runs just apply, with a Cloudflare token that can create account tokens. The state file holds every minted token, so it stays on that person's machine and is gitignored. If the state is lost, just apply mints new tokens and overwrites the secrets in each repo.

License

MIT. See LICENSE.

The logo files in docs/static/ are baskingspot marks and are not covered by the MIT license. See docs/static/LICENSE.

How it's made

Built with LLM assistance. How, in detail.

baskingspot

About

The router for baskingspot.dev, the Zig download mirror, and the Terraform that gives each library its own Worker.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages