Skip to main content

Module router

Module router 

Source
Expand description

Public axum router that the host app mounts.

Two flavours, each with a cache-enabled variant:

  • router — fallback-style. The CMS resolver is the router’s .fallback(), so any unmatched path renders as a page. Simple and correct for non-tenancy apps.
  • router_at — explicit-prefix style. Mounts the CMS at a non-root prefix via nest(prefix, /{*path}). Required when composing with rustango’s tenancy admin — see note below.

§Caching

Both have _cached variants that wrap the router with rustango::cache_page::CachePageLayer — a tower layer that caches successful GET responses on a (prefix, method, path, Host, vary-on) key and emits the matching Cache-Control / Vary headers. GET-only, 200-only; the layer respects a response’s own Cache-Control: no-store so individual handlers can opt out.

By default entries expire on TTL only, so editors see stale content for up to the TTL after a save. To purge on save, build a crate::cache_invalidate::BoxedCacheInvalidator over the same cache and pass it to crate::admin::router_with_invalidator; the admin then drops the affected keys after each page mutation.

Per-tenant scoping is automatic via the layer’s built-in Host- header partitioning. Vary on cookie / accept-language etc. via the layer’s vary_on(...) method when building via PublicRouter.

§Don’t use router with rustango tenancy

Rustango’s tenancy server::Builder used to attach its own admin as Router::fallback_service(tenant_admin) on the merged user router. Axum semantics: that override silenced any .fallback() set by the user’s router. As of rustango 0.31 the tenant admin mounts via explicit routes for routes.admin_url only, so router is allowed to claim site root — see examples/cms_demo.

Structs§

PublicRouter
Builder for the public CMS router. Use when you need to combine mount-prefix, response caching, and/or path-based locale resolution — the free router / router_at / *_cached functions are shortcuts for common combinations and don’t expose every knob.

Functions§

router
Build the CMS router using axum’s .fallback() for page rendering. Use only when the CMS is the sole surface — see the module docs for the tenancy gotcha.
router_at
Build the CMS router mounted under an explicit URL prefix.
router_at_cached
Like router_at, wrapped in rustango::cache_page::CachePageLayer. See router_cached for the trade-off (TTL-based invalidation).
router_cached
Like router, wrapped in rustango::cache_page::CachePageLayer. GET responses are cached for ttl keyed on (method, path, Host, vary-on); admin edits propagate after the TTL elapses (no manual invalidation).