summaryrefslogtreecommitdiff
path: root/src/handlers/mod.rs
blob: 9d5aa54fa26126332ccf627d2443da757122e9b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use axum::extract::DefaultBodyLimit;
use axum::middleware::{self};
use axum::routing::{get, post};
use axum::Router;
use sqlx::SqlitePool;
use tower_http::add_extension::AddExtensionLayer;
use tower_http::services::ServeDir;

use admin::{admin_healthcheck, admin_middleware, upload_story};
use frontend_builder::home;

use self::frontend_builder::{build_page, DummyProduct};

mod admin;
mod frontend_builder;

#[derive(Debug, Clone)]
struct ApiContext {
    pool: SqlitePool,
}

pub async fn router(pool: SqlitePool) -> Router {
    Router::new()
        .route("/admin/story", post(upload_story))
        .route("/admin", get(admin_healthcheck))
        .layer(middleware::from_fn(admin_middleware))
        .route("/", get(home))
        .route("/stories", get(build_page::<DummyProduct>))
        .nest_service("/static", ServeDir::new("src/static"))
        .layer(DefaultBodyLimit::max(1074000000))
        .layer(AddExtensionLayer::new(ApiContext { pool }))
}