Skip to main content

rustio_core/
defaults.rs

1//! Default routes that scaffolded projects mount via [`with_defaults`]:
2//! `/` (homepage) and `/docs` (placeholder).
3//!
4//! `/admin` is intentionally **not** registered here — it is owned by the
5//! admin layer (see [`crate::admin::Admin::register`]). If no admin models
6//! are registered, `/admin` is simply absent.
7
8use crate::error::Error;
9use crate::http::{html, text, Request, Response};
10use crate::router::{Params, Router};
11
12const HOME_HTML: &str = include_str!("../assets/home.html");
13
14pub fn homepage() -> Response {
15    html(HOME_HTML)
16}
17
18pub fn docs_placeholder() -> Response {
19    text("RustIO docs — coming soon.")
20}
21
22pub fn with_defaults(router: Router) -> Router {
23    router
24        .get("/", |_req: Request, _p: Params| async {
25            Ok::<Response, Error>(homepage())
26        })
27        .get("/docs", |_req: Request, _p: Params| async {
28            Ok::<Response, Error>(docs_placeholder())
29        })
30}