Skip to main content

Module base_path

Module base_path 

Source
Expand description

Reverse-proxy subpath support for lean-ctx dashboard --base-path (#355).

When the dashboard is mounted under a subpath (e.g. /dashboard/) by an nginx-style reverse proxy, two things must happen:

  1. Every root-absolute URL in the served HTML/CSS/JS (/static/…, /api/…, /favicon…) must be prefixed with the base path, otherwise the browser resolves them against the origin root and bypasses the subpath.
  2. The server must accept incoming requests both with and without the prefix, so it works whether or not the reverse proxy strips it.

All functions are pure and base-gated (empty base → exact no-op), so the default behaviour is byte-for-byte identical to a dashboard without a subpath.

Functions§

normalize
Normalizes a user-supplied base path into a canonical form: an empty string for “no prefix”, otherwise a single leading slash and no trailing slash.
rewrite_asset_urls
Prefixes every root-absolute asset/API/favicon URL in a served text body with the base path. Only the quote/paren-delimited forms that actually occur in the dashboard assets ("/static/, '/api/, `/api/, url(/static/, …) are rewritten, so ordinary text is never touched. No-op when base is empty.
strip
Strips the base-path prefix from an incoming request path so downstream routing always sees a root-relative path. Requests that already arrive root-relative (proxy stripped the prefix, or direct local access) pass through unchanged.