Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

11. Not-found page for missing routes

Date: 2026-11-23

Status

Accepted and implemented: the build writes a styled 404.html at the output root, and listsome serve returns that page (with a real 404 status) for routes that match no generated file. Unit test test_render_404_page in src/render/mod.rs, integration test the_build_emits_a_not_found_page in tests/example_site.rs, and the router tests in src/server/mod.rs (the_router_serves_the_not_found_page_with_a_404 and the_router_404s_without_a_built_page) cover it.

Context

A listsome site is static files behind a web server. When a path does not match a generated page, the server returns its default error unless the site ships a not-found page. Static hosts (GitHub Pages, Netlify, Cloudflare Pages) serve a root 404.html automatically, and nginx serves it with error_page 404 /404.html;. Before this change listsome emitted none, so a dead link rendered a bare, chrome-less server error instead of a page in the site’s voice.

This came up migrating an older site whose post URLs used a different scheme than listsome’s /<slug>/. Old permalinks 404 after cutover; low traffic makes a full redirect table not worth it, but the dead ends should still look like the site and offer a way home.

Decision

The build always writes 404.html at the output root, rendered from the shared base layout with a short “Not found” message and a link to /. It is emitted unconditionally: every site can use it, and a host that ignores it loses nothing. Resolution is the existing template path (a render_404 method and a write_404_page), so it carries the site header, footer, styles, and any custom CSS like any other page.

The development server reads that same file. Its static-file fallback hands any path that matches no output file to a handler that returns 404.html with an explicit 404 status and an HTML media type, so listsome serve behaves like a static host instead of returning the blank 404 a bare file server would. When the page has not been built yet it falls back to a minimal not-found body, still under 404, never a soft 200.

Consequences

  • Static hosts and an nginx error_page 404 /404.html; line get a real page for free; no server change is required for the common hosts that auto-discover 404.html.
  • listsome serve shows the same page for an unknown route, so a not-found in development matches production. The response keeps the 404 status, so it stays a true error rather than a soft 200.
  • It is not a redirect system. URLs that moved still return 404. A redirect map remains a host-level concern, out of scope, in keeping with the roadmap, which holds that listsome does not rewrite or redirect paths.
  • A build now produces one extra file at the root. Harmless to diff-based deploys.