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

Public Routes

A module mounts an endpoint outside the admin: a feed, a robots.txt, a webhook. No session, no permission, no admin chrome.

Mount a public route

use laterite_admin::axum::{routing::get, Router};
use laterite_admin::routes::{PublicRoute, PublicRouteReg, RouteCtx};

struct Robots;

impl PublicRoute for Robots {
    fn mount(&self, _ctx: &RouteCtx) -> Router {
        Router::new().route("/", get(robots_txt))
    }
}

registry.add_public_route(PublicRouteReg::new("/robots.txt", Arc::new(Robots)));
PublicRouteRegDescription
new(path, route)path is literal, never namespaced. A route inside the admin mount is refused.

A POST must come from the site’s own origin. A route that authenticates each request itself (an API token, a signed webhook) leaves that check:

registry.add_public_route(
    PublicRouteReg::new("/api/capture", Arc::new(Capture)).skip_origin_check(),
);
PublicRouteRegDescription
skip_origin_check()The path and everything below it skip the origin check. The route verifies each request.

A path can also be listed in backend.origin_check_except. See Admin. ctx.url, ctx.base_url, middleware and other modules’ contributions work as on an admin screen.