Skip to main content

Module path_prefix

Module path_prefix 

Source
Expand description

Sites served under a path on the main domain (example.com/acme/) rather than on a host of their own.

The framework sends a path-prefix tenant’s requests to the host app with the prefix still on the path (/acme/about), but every CMS route, page path and link is written from the site’s root. serve wraps the host’s router so a site works the same under a prefix:

  • on the way in, the prefix comes off the path (/acme/about is served as /about). The framework finds the tenant again in every handler from the request, which no longer shows the prefix, so the site is named in a header the host’s resolver reads (tenant_header); a copy sent by the client is always dropped first;
  • on the way out, it goes back on: redirects, cookie paths, and the root-relative addresses in HTML, CSS, JavaScript and JSON (links, pictures, forms, and the admin’s own /cms-admin/… calls). Absolute addresses (sitemap, feeds, robots.txt) carry it through PREFIX_HEADER.

A host wires both halves:

ⓘ
rustango::manage::Cli::new()
    .tenancy()
    .tenant_header(rustango_cms::path_prefix::tenant_header())
    .api(rustango_cms::path_prefix::serve(api))

Sites on their own host pass through untouched.

Constants§

PREFIX_HEADER
The prefix taken off the request (/acme). Set only by serve; absolute addresses add it after the host.
TENANT_HEADER
Names the site a stripped request belongs to, for the framework’s resolver. Set only by serve.

Functions§

of
The prefix serve took off this request, if any.
serve
router, serving path-prefix sites from their prefix.
site_path
path as the site sees it: without the prefix serve took off this request. For addresses the browser reports (location.pathname).
tenant_header
The resolver that finds a stripped request’s site, for Cli::tenant_header.