2024-07-27 13:20:31 -04:00
|
|
|
use crate::html::{api, blog, AppState};
|
2024-04-28 11:02:16 -04:00
|
|
|
use axum::{
|
2024-07-27 13:20:31 -04:00
|
|
|
http::StatusCode,
|
2024-04-28 11:02:16 -04:00
|
|
|
response::{IntoResponse, Redirect},
|
|
|
|
|
routing::{get, Router},
|
2024-04-28 20:23:19 -04:00
|
|
|
Extension,
|
2024-04-28 11:02:16 -04:00
|
|
|
};
|
2024-04-28 20:23:19 -04:00
|
|
|
use sqlx::PgPool;
|
2024-03-24 10:45:16 -04:00
|
|
|
use tower_http::services::ServeDir;
|
|
|
|
|
|
2024-07-27 13:20:31 -04:00
|
|
|
use super::{garden, get_page};
|
2024-04-28 20:23:19 -04:00
|
|
|
|
|
|
|
|
pub fn get_router(pool: PgPool) -> Router {
|
2024-03-24 10:45:16 -04:00
|
|
|
let assets_path = std::env::current_dir().unwrap();
|
2024-04-28 20:23:19 -04:00
|
|
|
let state = AppState { db: pool };
|
2024-03-24 10:45:16 -04:00
|
|
|
Router::new()
|
2024-04-28 20:23:19 -04:00
|
|
|
.nest("/api", api::get_router())
|
|
|
|
|
.nest("/blog", blog::get_router())
|
2024-07-27 13:20:31 -04:00
|
|
|
.nest("/garden", garden::get_router())
|
2024-04-28 20:23:19 -04:00
|
|
|
.nest_service(
|
|
|
|
|
"/assets",
|
|
|
|
|
ServeDir::new(format!("{}/assets", assets_path.to_str().unwrap())),
|
|
|
|
|
)
|
2024-03-24 10:45:16 -04:00
|
|
|
.route("/", get(home))
|
|
|
|
|
.route("/now", get(now))
|
|
|
|
|
.route("/about", get(about))
|
|
|
|
|
.route("/contact", get(contact))
|
2024-07-05 20:00:43 -04:00
|
|
|
.route("/uses", get(uses))
|
2024-08-09 16:22:14 -04:00
|
|
|
.route("/ai", get(ai))
|
2024-04-28 11:02:16 -04:00
|
|
|
.route(
|
|
|
|
|
"/robots.txt",
|
|
|
|
|
get(|| async { Redirect::permanent("/assets/robots.txt") }),
|
|
|
|
|
)
|
2024-04-28 20:23:19 -04:00
|
|
|
.layer(Extension(state))
|
2024-03-24 10:45:16 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-27 13:20:31 -04:00
|
|
|
async fn home(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
|
|
|
|
|
get_page(&state.db, "home").await
|
2024-03-24 15:12:36 -04:00
|
|
|
}
|
2024-03-24 10:45:16 -04:00
|
|
|
|
2024-07-27 13:20:31 -04:00
|
|
|
async fn now(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
|
|
|
|
|
get_page(&state.db, "now").await
|
2024-03-24 10:45:16 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-27 13:20:31 -04:00
|
|
|
async fn about(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
|
|
|
|
|
get_page(&state.db, "about").await
|
2024-03-24 10:45:16 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-27 13:20:31 -04:00
|
|
|
async fn contact(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
|
|
|
|
|
get_page(&state.db, "contact").await
|
2024-03-24 10:45:16 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-27 13:20:31 -04:00
|
|
|
async fn uses(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
|
|
|
|
|
get_page(&state.db, "uses").await
|
2024-07-05 20:00:43 -04:00
|
|
|
}
|
2024-08-09 16:22:14 -04:00
|
|
|
|
|
|
|
|
async fn ai(state: Extension<AppState>) -> Result<impl IntoResponse, StatusCode> {
|
|
|
|
|
get_page(&state.db, "ai").await
|
|
|
|
|
}
|