`configure_router()` recibe Routes, que no monta ninguna ruta sin su Access: `route()`, `public_route()` y `admin_route()`, que toma el permiso de la página del panel de la que cuelga. Una ruta del panel montada de otra forma impide arrancar. `configure_middleware()` recibe Layers y `configure_static_files()` recibe StaticFiles, siempre públicos.
29 lines
679 B
Rust
29 lines
679 B
Rust
use pagetop::prelude::*;
|
|
|
|
struct HelloName;
|
|
|
|
#[async_trait]
|
|
impl Extension for HelloName {
|
|
fn configure_router(&self, routes: Routes) -> Routes {
|
|
routes.public_route("/hello/{name}", web::get(hello_name))
|
|
}
|
|
}
|
|
|
|
async fn hello_name(
|
|
request: HttpRequest,
|
|
web::Path(name): web::Path<String>,
|
|
) -> Result<Markup, ErrorPage> {
|
|
Page::new(request)
|
|
.with_child(Html::with(move |_| {
|
|
html! {
|
|
h1 style="text-align: center;" { "Hello " (name) "!" }
|
|
}
|
|
}))
|
|
.render()
|
|
.await
|
|
}
|
|
|
|
#[pagetop::main]
|
|
async fn main() -> std::io::Result<()> {
|
|
Application::prepare(&HelloName).await.run().await
|
|
}
|