📝 Document route access and custom authentication

Adapt the guides to the current PageTop API: Routes with the access of
each route, Layers, StaticFiles and the administration panel in the
core, with pagetop-admin reduced to the settings forms.

Add the "Connect your own authentication" guide, the mail test page and
the admin_path setting, and explain route access in the architecture
page.

Mount the books with their access through pagetop-mdbook.
This commit is contained in:
Manuel Cillero 2026-11-07 17:24:26 +01:00
parent f42f5e9b89
commit 345bd26974
41 changed files with 869 additions and 368 deletions

View file

@ -37,8 +37,8 @@ pub struct Garden;
#[async_trait]
impl Extension for Garden {
fn configure_middleware(&self, router: Router) -> Router {
router.layer(web::middleware::from_fn(timing))
fn configure_middleware(&self, layers: Layers) -> Layers {
layers.layer(web::middleware::from_fn(timing))
}
}
```
@ -71,8 +71,8 @@ use tower_http::timeout::TimeoutLayer;
# pub struct Garden;
# #[async_trait]
# impl Extension for Garden {
fn configure_middleware(&self, router: Router) -> Router {
router
fn configure_middleware(&self, layers: Layers) -> Layers {
layers
// Requests with a body over 1 MiB get a 413 Payload Too Large.
.layer(RequestBodyLimitLayer::new(1024 * 1024))
// Requests that take more than 30 seconds get a 408 Request Timeout.
@ -107,8 +107,8 @@ inicializaron antes.
## 4. Aplica una capa sólo a tus rutas
`configure_middleware()` afecta a todo. Para que una capa sólo envuelva unas rutas, crea con ellas
un `Router` propio en `configure_router()`, ponle la capa y únelo al resto con `merge()`. Es lo
natural para CORS, que sólo debe abrirse en la API:
un `Router` propio en `configure_router()`, ponle la capa y anídalo bajo su prefijo con `nest()`,
con el acceso que compartan sus rutas. Es lo natural para CORS, que sólo debe abrirse en la API:
```rust,no_run
# use pagetop::prelude::*;
@ -122,16 +122,18 @@ use tower_http::cors::CorsLayer;
# pub struct Garden;
# #[async_trait]
# impl Extension for Garden {
fn configure_router(&self, router: Router) -> Router {
fn configure_router(&self, routes: Routes) -> Routes {
let cors = CorsLayer::new()
.allow_origin(web::http::HeaderValue::from_static("https://garden.example.org"))
.allow_methods([web::http::Method::GET]);
let api = Router::new()
.route("/api/plots", web::get(plots))
.route("/plots", web::get(plots))
.layer(cors);
router.route("/", web::get(home)).merge(api)
routes
.public_route("/", web::get(home))
.nest("/api", Access::Public, api)
}
# }
```
@ -170,8 +172,8 @@ struct Garden;
#[async_trait]
impl Extension for Garden {
fn configure_middleware(&self, router: Router) -> Router {
router
fn configure_middleware(&self, layers: Layers) -> Layers {
layers
.layer(web::middleware::from_fn(timing))
.layer(RequestBodyLimitLayer::new(1024 * 1024))
.layer(TimeoutLayer::with_status_code(
@ -181,19 +183,19 @@ impl Extension for Garden {
.layer(CompressionLayer::new())
}
fn configure_router(&self, router: Router) -> Router {
fn configure_router(&self, routes: Routes) -> Routes {
let cors = CorsLayer::new()
.allow_origin(web::http::HeaderValue::from_static("https://garden.example.org"))
.allow_methods([web::http::Method::GET]);
let api = Router::new()
.route("/api/plots", web::get(plots))
.route("/plots", web::get(plots))
.layer(cors);
router
.route("/", web::get(home))
.route("/notes", web::post(notes))
.merge(api)
routes
.public_route("/", web::get(home))
.public_route("/notes", web::post(notes))
.nest("/api", Access::Public, api)
}
}