summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: 43142928d63bc814dc5df4cb1011d9d4d04d3a45 (plain) (blame)
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
33
use axum::{routing::get, Router};
use tutors::fs_tutor_repo::FsTutorRepo;
use std::sync::Arc;
use tower_http::services::ServeDir;
use posts::fs_post_repo::FsPostRepo;

mod helpers;
mod posts;
mod tutors;
mod views;
mod handlers;

#[tokio::main]
async fn main() {
    let posts = Arc::new(FsPostRepo::with_dir(format!("/data/ct/{}", "blog")));
    let tutors = Arc::new(FsTutorRepo::with_dir(format!("/data/ct/{}", "team")));

    let app = Router::new()
        .route("/", get(handlers::index_handler))
        .route("/posts", get(handlers::posts_handler))
        .route("/posts/:post_id", get(handlers::post_handler))
        .with_state(posts)
        .route("/policies", get(handlers::policies_handler))
        .route("/brochure", get(handlers::brochure_handler))
        .route("/about", get(handlers::about_handler))
        .with_state(tutors)
        .nest_service("/assets", ServeDir::new("/data/ct/assets"))
        .nest_service("/team", ServeDir::new("/data/ct/team"))
        .fallback_service(ServeDir::new("static"));

    let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await.unwrap();
    axum::serve(listener, app).await.unwrap();
}