use std::sync::Arc; use tokio::sync::RwLock; use blog::{Blog, RenderedBlog}; use warp::{path::FullPath, Filter}; mod blog; mod date; mod parser; mod post; async fn handle_request( req: FullPath, blog: Arc<RwLock<RenderedBlog>>, ) -> Result<impl warp::Reply, warp::Rejection> { let blog = blog.read().await; let (status, content) = blog.get(req.as_str()); let content = content.to_owned(); Ok(warp::reply::with_status(warp::reply::html(content), status)) } #[tokio::main] async fn main() { let blog: RenderedBlog = Blog::new().unwrap().try_into().unwrap(); let blog = Arc::new(RwLock::new(blog)); let blog_filter = warp::any().map(move || blog.clone()); warp::serve( warp::filters::path::full() .and(blog_filter.clone()) .and_then(handle_request), ) .run(([0, 0, 0, 0], 3030)) .await; }