#[macro_use] extern crate tracing; use color_eyre::eyre::Result; use std::{net::IpAddr, sync::Arc}; use warp::{Filter, path}; use std::str::FromStr; pub mod blog; pub mod misc; mod internal; use internal::SiteState; #[tokio::main] async fn main() -> Result<()> { color_eyre::install()?; tracing_subscriber::fmt::init(); info!("Starting launch of {}", env!("GIT_SHA")); // Load .env kankyo::init(); let state = Arc::new(internal::init().await?); let index = warp::get().and(path::end().and_then(misc::handlers::index)); let blog_base = warp::path!("blog" / ..); let blog_list = blog_base.and(give_site_state(state.clone())).and_then(blog::handlers::list); let blog_post = blog_base.and( warp::path!(String) .and(give_site_state(state.clone())) .and_then(blog::handlers::post), ); let static_files = warp::path("static") .and(warp::fs::dir("./statics")); let site = index .or(blog_list.or(blog_post)) .or(static_files).with(warp::log("site")); let server = warp::serve(site); server .run(( IpAddr::from_str(&std::env::var("HOST").unwrap_or("127.0.0.1".into()))?, std::env::var("PORT") .unwrap_or("3030".into()) .parse::()?, )) .await; Ok(()) } fn give_site_state(sitestate: Arc) -> impl Filter,), Error=std::convert::Infallible> + Clone { warp::any().map(move || sitestate.clone()) } include!(concat!(env!("OUT_DIR"), "/templates.rs"));