TutorialPost
Shipping it with a systemd unit
The last chapter puts the server on a real machine: a user of its own, a unit file, logs in journald and a restart when it falls over.
Mira Okafor Backend notes from Weststadt. Tutorials in chapters, short notes in between, and the release log of stummel.
Series
Six chapters from an empty file to a server with routes, middleware, tests and a systemd unit. No framework, Node 24 and nothing else.
Start with chapter 1TutorialPost
The last chapter puts the server on a real machine: a user of its own, a unit file, logs in journald and a restart when it falls over.
TIL
Since curl 7.82, --json sends the body as data and sets Content-Type and Accept to application/json in one go.
$ curl --json '{"url":"https://example.org/a/long/path"}' localhost:8080/api/links
{"code":"k3x9","url":"https://example.org/a/long/path"}Before, I typed -H twice and forgot one of them every other time.
TutorialPost
Node ships a test runner. Twelve tests cover the router and the middleware, and none of them opens a port.
Letter
Changelog
Links can expire after a date or a number of clicks, and the API answers 410 for them. The link list now comes wrapped in an object.
A link can carry expires_at or max_clicks now, and stummel answers 410 Gone once either is reached. Half the links people asked me to delete were for events that were over.GET /api/links returns { "links": [...], "next": "..." } instead of a bare array, so the list can page. Update your client before you upgrade.Added
expires_at and max_clicks on a link, in the API and the form.410 Gone with a short page instead of 404.GET /api/links with next.Changed
GET /api/links wraps the list in links.Fixed
-const links: Link[] = await res.json();
+const { links, next } = await res.json() as { links: Link[]; next?: string };
TIL
\x auto switches psql to one column per row only when a row is wider than the terminal. Narrow results stay a table.
$ echo '\x auto' >> ~/.psqlrcI used to toggle \x by hand and forget to toggle it back.
Post
node --watch restarts the process when a file it loaded changes. It replaced a dependency and a config file in stummel.
1 min
Incident
The certificate expired at 06:00. Renewal had failed for three weeks, and the warning mails went to a folder I never open.
Resolved
Major
Every short link answered with a certificate error for 47 minutes on Wednesday morning. The certificate expired at 06:00 CEST. Its renewal had failed every night for three weeks, and each failure sent a mail that a filter of mine moved into a folder I never open. I closed port 80 when I moved the server, because stummel only serves HTTPS. The HTTP-01 challenge needs port 80. Renewal failed quietly for 21 nights.Timeline
What went wrong
What changed
TutorialPost
A middleware is a function that takes a handler and returns a handler. Logging and a token check, nested without a framework.
Post
We parsed query strings by hand for an afternoon, then deleted it and used URLSearchParams. Notes from both sides of the keyboard.
1 min
Changelog
A short link with ?ref= passes it on to the target now. One fix, no breaking change.
A short link called with a query string passes it on to the target, so /k3x9?ref=mail lands on …/path?ref=mail. Three people asked for this in a week.Fixed
&.
TIL
git worktree add checks out a second branch in its own folder. The half-done work stays where it is.
$ git worktree add ../stummel-hotfix main
$ cd ../stummel-hotfix
$ git switch -c fix/query-stringgit worktree remove ../stummel-hotfix cleans up once it is merged.