use std::{collections::HashMap, sync::Arc}; use color_eyre::eyre::{Error, Result}; use post::Post; use tag::Tag; use tera::Tera; use tower_http::{compression::CompressionLayer, trace::TraceLayer, cors::CorsLayer}; use tracing::log::*; mod handlers; mod post; mod tag; pub struct AppState { posts: HashMap, tags: HashMap, tera: Tera, } #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; tracing_subscriber::fmt::init(); info!("Starting server..."); let tera = Tera::new("templates/**/*")?; let posts = post::load_all().await?; let tags = tag::get_tags(posts.values()); let state = Arc::new(AppState { tera, posts, tags }); let app = handlers::routes(&state) .layer(CorsLayer::permissive()) .layer(TraceLayer::new_for_http()) .layer(CompressionLayer::new()) .with_state(state); info!("Now listening at http://localhost:8180"); axum::Server::bind(&"0.0.0.0:8180".parse().unwrap()) .serve(app.into_make_service()) .await?; Ok(()) } #[derive(Debug)] pub enum WebsiteError { NotFound, InternalError(Error), } impl From for WebsiteError where E: Into, { fn from(value: E) -> Self { WebsiteError::InternalError(value.into()) } }