2022-03-16 03:26:18 +00:00
|
|
|
mod json_handlers;
|
|
|
|
|
2022-03-16 04:10:21 +00:00
|
|
|
use warp::{Filter, Rejection};
|
2022-03-16 03:26:18 +00:00
|
|
|
|
|
|
|
#[tokio::main]
|
|
|
|
async fn main() {
|
|
|
|
let route = warp::body::content_length_limit(1024 * 32)
|
2022-03-16 04:09:07 +00:00
|
|
|
.and(warp::body::bytes())
|
|
|
|
.and_then(|bytes: bytes::Bytes| async move {
|
|
|
|
let body_str_result = std::str::from_utf8(bytes.as_ref());
|
|
|
|
if let Ok(body_str) = body_str_result {
|
|
|
|
let json_result = serde_json::from_str(body_str);
|
|
|
|
if let Ok(json_value) = json_result {
|
|
|
|
Ok(json_handlers::handle_json(json_value).unwrap_or_else(|e| e))
|
|
|
|
} else {
|
|
|
|
Ok(String::from("{\"type\": \"invalid_syntax\"}"))
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ok::<String, Rejection>(String::from("{\"type\": \"invalid_syntax\"}"))
|
|
|
|
}
|
2022-03-16 03:26:18 +00:00
|
|
|
});
|
|
|
|
|
2022-03-16 03:31:18 +00:00
|
|
|
warp::serve(route).run(([0, 0, 0, 0], 1237)).await;
|
2022-03-14 05:33:51 +00:00
|
|
|
}
|