use std::{collections::HashMap, sync::Arc}; use axum::{body, response::Response, routing::get, Extension, Router, extract::State}; use color_eyre::eyre::{Error, Result}; use hyper::header::CONTENT_TYPE; use post::Post; use prometheus::{Encoder, TextEncoder}; use tera::Tera; use tower_http::{compression::CompressionLayer, trace::TraceLayer}; use tracing::log::*; mod handlers; mod post; pub struct AppState { posts: 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 state = Arc::new(AppState { tera, posts }); let app = handlers::routes(&state) .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()) } }