This commit is contained in:
Dominik Werder
2021-05-14 10:30:54 +02:00
parent 70426e8e48
commit 8dc80f5dba
12 changed files with 159 additions and 47 deletions

View File

@@ -83,6 +83,21 @@ where
impl<F> UnwindSafe for Cont<F> {}
macro_rules! static_http {
($path:expr, $tgt:expr, $tgtex:expr) => {
if $path == concat!("/api/4/documentation/", $tgt) {
let c = include_bytes!(concat!("../static/documentation/", $tgt, $tgtex));
return Ok(response(StatusCode::OK).body(Body::from(&c[..]))?);
}
};
($path:expr, $tgt:expr) => {
if $path == concat!("/api/4/documentation/", $tgt) {
let c = include_bytes!(concat!("../static/documentation/", $tgt));
return Ok(response(StatusCode::OK).body(Body::from(&c[..]))?);
}
};
}
async fn data_api_proxy_try(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Response<Body>, Error> {
let uri = req.uri().clone();
let path = uri.path();
@@ -122,6 +137,14 @@ async fn data_api_proxy_try(req: Request<Body>, node_config: &NodeConfigCached)
} else {
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
}
} else if path.starts_with("/api/4/documentation/") {
if req.method() == Method::GET {
static_http!(path, "", "index.html");
static_http!(path, "page.css");
Ok(response(StatusCode::NOT_FOUND).body(Body::empty())?)
} else {
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
}
} else {
Ok(response(StatusCode::NOT_FOUND).body(Body::from(format!(
"Sorry, not found: {:?} {:?} {:?}",