summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: fb15e5189513ca2b2ff9eb81e5b8c90425ceccee (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
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))
        .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();
}