You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.0 KiB

mod handlers;
4 years ago
use warp::{
4 years ago
Filter,
Rejection,
Reply,
4 years ago
body
4 years ago
};
4 years ago
use env_logger;
4 years ago
use u_lib::{
MASTER_PORT,
4 years ago
contracts::*,
4 years ago
};
4 years ago
fn get_content() -> impl Filter<Extract = (Message<'static, ClientInfo>,),
Error = Rejection> + Clone {
4 years ago
body::content_length_limit(1024*64).and(body::json::<Message<ClientInfo>>())
}
4 years ago
#[tokio::main]
async fn main() {
env_logger::init();
let base_db = Storage::new();
let db = warp::any().map(move || base_db.clone());
4 years ago
let new_client = warp::post()
.and(warp::path("init"))
4 years ago
.and(get_content())
.and(db.clone())
.and_then(handlers::add_client);
4 years ago
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);
4 years ago
4 years ago
let routes = new_client
.or(auth_zone)
4 years ago
.with(warp::log("warp"));
4 years ago
warp::serve(routes)
4 years ago
.run(([0,0,0,0], MASTER_PORT)).await;
4 years ago
}