Files
Bit.Auth-r/src/url/api/mod.rs
2024-07-15 08:37:45 +03:00

37 lines
811 B
Rust

mod v0;
mod v1;
use {
hyper::{
StatusCode,
Request,
header::HeaderValue,
body::{
Incoming,
},
},
serde_json::{
Value as Json,
json,
},
skytable::pool::ConnectionMgrTcp,
bb8::Pool,
std::sync::Arc,
};
type DBPool = Arc<Pool<ConnectionMgrTcp>>;
pub async fn endpoint(req: Request<Incoming>, pool: DBPool) -> (String, StatusCode, HeaderValue) {
let uri: &str = req.uri().path().as_ref();
let res: Json = match &uri[4..uri.len()] {
"/test" => json!({"error": false, "msg": "test"}),
x if x.starts_with("/v0/") => v0::api(req, pool.clone()).await,
x if x.starts_with("/v1/") => v1::api(req, pool.clone()).await,
_ => json!({"error": true, "msg": "No endpoint"})
};
let restype: HeaderValue = "application/json".parse().unwrap();
(res.to_string(), StatusCode::OK, restype)
}