mod handlers; use warp::{ Filter, Rejection, Reply, body }; use env_logger; use u_lib::{ MASTER_PORT, contracts::*, }; fn get_content() -> impl Filter,), Error = Rejection> + Clone { body::content_length_limit(1024*64).and(body::json::>()) } #[tokio::main] async fn main() { env_logger::init(); let base_db = Storage::new(); let db = warp::any().map(move || base_db.clone()); let new_client = warp::post() .and(warp::path("new")) .and(get_content()) .and(db.clone()) .and_then(handlers::add_client); let ls = warp::get() .and(warp::path("ls")) .and(db.clone()) .and_then(handlers::listing); let auth_token = warp::header::exact("authorization", "Bearer 123qwe"); let auth_zone = auth_token.and(ls); let routes = new_client .or(auth_zone) .with(warp::log("warp")); warp::serve(routes) .run(([0,0,0,0], MASTER_PORT)).await; }